I have an Aurelia application where the user can select the company they\'re currently \"working on\". Every page in the app is dependent on the currently selected company,
While not officially supported, there are a variety of hacks suggestions in a relevant GitHub issue asking for this very functionality.
The one I got to work that does not involve updating aurelia's source code nor adding superfluous data to the route is to set the activationStrategy on all of my routes to be invokeLifecycle
instead of the default, like so:
import { activationStrategy } from 'aurelia-router';
export class App {
configureRouter(config, router) {
config.map([
{
route: ['', 'home'],
name: 'home',
moduleId: 'home/index',
activationStrategy: activationStrategy.invokeLifecycle
},
{
route: 'users',
name: 'users',
moduleId: 'users/index',
nav: true,
activationStrategy: activationStrategy.invokeLifecycle
},
... etc ...
]);
}
}
This makes it so the route's activate()
method will run as you expect when the view model is reloaded. Then, in the code that initiates the reload, I do the following:
this.router.navigateToRoute(
this.router.currentInstruction.config.name,
this.router.currentInstruction.params,
{ replace: true }
);