我有3个级别的嵌套的路由器,这样的定义:使用与奥里利亚子路由器命名路由
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.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;
}
我想导航到第三级,它可以使用普通链接标记或直接在URL中输入(例如, <a href="#/accounting/accounts/view/2">
),但没有下面的方法来命名路由工作:
- (从app.html,1级试图访问3级)
<a route-href="route: accounting-account-list">Account List</a>
- (从app.html,1级试图访问3级)
<a route-href="route: accounting-account-view; params.bind: {id: 2}">Account #2</a>
- (来自会计-home.js,级别2尝试访问第3级)
this.router.navigateToRoute('accounting-account-view', {id: 2});
- (来自会计-home.js,级别2尝试访问第3级)
this.router.navigateToRoute('accounting/accounting-accounts/accounting-account-view', {id: 2});
对于#1-2,当应用加载时,我收到了控制台日志错误,如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.
,并且链接已死亡。
对于#3-4,我越来越控制台日志错误,如Uncaught Error: A route with name 'accounting-account-view' could not be found.
我也越来越像很多在控制台日志Warning: a promise was rejected with a non-error: [object Object] at _buildNavigationPlan
警告在页面加载时,每次我导航。
我在做什么错?我需要做一些特殊的事情来访问不同路由器级别的路由吗?
小问题:我需要在每个视图中都有import {Router} from 'aurelia-router';
模型,有些还是没有?我需要注入吗?
我想你需要简化你的路由方案!但是,严重的是,如果没有其他人,我会尽力回答。 –
在https://scottwhittaker.net/aurelia/2016/06/12/aurelia-router-demo.html有一个很好的演示,但它没有解决命名路线的使用问题。 – LStarky
谢谢!我会很感激帮助! – LStarky