Meirion Hughes
Meirion Hughes

Reputation: 26398

Aurelia: Add/Remove router.navigation Routes dynamically?

Is it possible to reconfigure a router.navigation to add/remove specific routes, and say have router.navigation automatically update the view?

My use case will be to have a route for multiple pages i.e. /page/A, /page/B and then to allow adding more while the app is running /page/C. I also want the navigation to show those specific pages in the menu: "Page A", "Page B" "Page C"

I believe there are parametrised routes available (route: 'page/:id'). But its not clear if you can give some context to the router.navigation to add some specific routes, via the parametrised route config.

Upvotes: 4

Views: 2317

Answers (1)

Carlos Mantilla
Carlos Mantilla

Reputation: 413

Try this to add route:

this.router.addRoute({ route: "pageA", moduleId: "views/pageA", nav: true, title: "PageA" });
this.router.refreshNavigation();

To remove: Inspect the Navigation model an remove the route that you want.

Upvotes: 1

Related Questions