[英]Is my router.js is correct?
嗨,當我嘗試在瀏覽器中訪問到dashboard/posts/id/comments
路線時,出現UnrecognizedUrl
錯誤。 以下是我的router.js
我想問一下我的路由器是否wrong
或者有人可以告訴我正確的方法
this.route('dashboard', function() {
this.route('posts', function() {
this.route('show', { path: ':post_id' }, function() {
this.route('comments', { path: ':post_id/comments'}, function() { });
});
});
});
但是,如果我將{{outlet}}
放在資源文件app/pods/dashboard/posts/show/template.hbs
它的確會顯示我放在app/pods/dashboard/posts/show/comments/template.hbs
時,我改變了我的router.js
到
this.route('dashboard', function() {
this.route('posts', function() {
this.route('show', { path: ':post_id' }, function() {
this.route('comments');
});
});
});
我的目標是我要在其他頁面上app/pods/dashboard/posts/show/comments/template.hbs
,該頁面在瀏覽器URL中應為dashboard/posts/id/comments
應該像
this.route('dashboard', function() {
this.route('routeA', function() {
this.route('childRouteA', { path: '/:childRouteA_id' }, function() {
this.route('childRouteAb');
});
});
});
例如: 儀表板/ routeA / id / childRouteAb
如果childRouteAb
是動態ID,則應類似於
this.route('dashboard', function() {
this.route('routeA', function() {
this.route('childRouteA', { path: '/:childRouteA_id' }, function() {
this.route('childRouteAb', { path: '/:childRouteAb'});
});
});
});
例如: 儀表板/路線A / ID / ID2
如果需要url在id之前指定id的類型,則可以這樣做。
this.route('dashboard', function() {
this.route('routeA', function() {
this.route('childRouteA', { path: '/childRouteA/:childRouteA_id' }, function() {
this.route('childRouteB', { path: '/childRouteB/:childRouteB_id'});
});
});
});
例如: 儀表板/ routeA / childRouteA / id1 / childRouteB / id2
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.