I have a navbar with the router links like in the Aurelia skeleton, but I want to also have parameterized links inside the router-view that change the router-view. Is this possible? If so, how do I access the router which is on App.ts? Any help is appreciated, thanks.
0
votes
1 Answers
2
votes
You just have to inject the router in your view-model. Like this:
import { autoinject } from 'aurelia-framework';
import { Router } from 'aurelia-router';
@autoinject
export class MyScreenInRouterView {
constructor(router: Router) {
this.router = router;
}
}
To use it in your view:
<a route-href="route: routeName; params.bind: { id: user.id }">${user.name}</a>
To generate URLs in code:
this.url = this.router.generate('routeName', { id: 123 });
To navigate to a route:
this.router.navigateToRoute('routeName', { id: 123 });
More information at http://aurelia.io/hub.html#/doc/article/aurelia/framework/latest/cheat-sheet/7