我有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