[英]Ember.js 2. Nested routes but non-nested templates
首先,感謝大家在本論壇中所做的努力。
我有這種情況:
我需要這樣的網址:
mysite.com/author/1/1/cart
但我不希望使用嵌套模板(每個頁面都不同,並且我不想在多個頁面中使用相同的信息)。
有沒有辦法獲得該URL?
我實際的router.js是這樣的:
Router.map(function() {
this.route('index', {path: '/'});
this.route('login');
this.route('authors', {path: '/authors'});
this.route('author', {path: '/author/:author_id'});
this.route('book', {path: '/book/:book_id'});
this.route('cart', {path: '/cart/:cart_id'});
});
您有兩種選擇:
只是不要嵌套您的路線,而是有多個動態細分。 那是可能的:
this.route('cart', {path: '/cart/:author_id/:cart_id'});
這將為您提供如下路線:
/cart/1/A
這將顯示作者1和購物車A的cart
路線
因此,您可以擁有此路由器:
this.route('author', {path: '/author/:author_id'}, function() {
this.route('cart', {path: '/cart/:cart_id'});
});
現在的問題是,如果將作者數據放入/author
路由中,那么它也可以在author.cart
路由上author.cart
。 但是一種簡單的解決方案是僅以{{outlet}}
為模板,將author
路由保留為空,然后將您的作者內容放入author.index
路由中。
這將為您提供如下路線:
/author/1
這將與author 1一起呈現author.index
路由
/author/1/cart/A
這將使用作者1和購物車A呈現author.cart
路線
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.