I have 3 levels of nested routers, defined like this:
app.js
configureRouter(config, router) {
this.router = router;
config.title = 'EagleWeb';
var step = new AuthorizeStep(this.core);
config.addAuthorizeStep(step);
config.map([
{ route: '', redirect: 'home' },
{ route: 'home', name: 'home', moduleId: 'home/home' },
{ route: 'users', name: 'users', moduleId: 'users/user-home' },
{ route: 'accounting', name: 'accounting', moduleId: 'accounting/accounting' }
]);
}
accounting/accounting.js
configureRouter(config, router) {
config.map([
{ route: '', redirect: 'home' },
{ route: 'home', name: 'accounting-home', moduleId: 'accounting/accounting-home' },
{ route: 'accounts', name: 'accounting-accounts', moduleId: 'accounting/accounts/accounts' },
{ route: 'entries', name: 'accounting-entries', moduleId: 'accounting/entries/entries' }
]);
this.router = router;
}
accounting/accounts/accounts.js
configureRouter(config, router) {
config.map([
{ route: '', redirect: 'list' },
{ route: 'list', name: 'accounting-account-list', moduleId: 'accounting/accounts/account-list' },
{ route: 'view/:id', name: 'accounting-account-view', moduleId: 'accounting/accounts/account-view' }
]);
this.router = router;
}
I want to navigate to the third level, and it works to use normal link tags or type directly in the URL (e.g. <a href="#/accounting/accounts/view/2">
) but none of the following approaches to named routes work:
- (from app.html, level 1 trying to access level 3)
<a route-href="route: accounting-account-list">Account List</a>
- (from app.html, level 1 trying to access level 3)
<a route-href="route: accounting-account-view; params.bind: {id: 2}">Account #2</a>
- (from accounting-home.js, level 2 trying to access level 3)
this.router.navigateToRoute('accounting-account-view', {id: 2});
- (from accounting-home.js, level 2 trying to access level 3)
this.router.navigateToRoute('accounting/accounting-accounts/accounting-account-view', {id: 2});
For #1-2, I'm getting console log errors like Error: A route with name 'accounting-account-list' could not be found. Check that name: 'accounting-account-list' was specified in the route's config.
when the app loads, and the links are dead.
For #3-4, I'm getting console log errors like Uncaught Error: A route with name 'accounting-account-view' could not be found.
I'm also getting lots of warnings like Warning: a promise was rejected with a non-error: [object Object] at _buildNavigationPlan
in the console log when the page loads and every time I navigate.
What am I doing wrong? Do I need to do something special to access the routes of a different router level?
Side questions: Do I need to import {Router} from 'aurelia-router';
in every view-model, some, or none? Do I need to inject it?