0

首先,感谢大家为本论坛所做的努力。

我有这种情况:

  • mysite.com/authors(作者列表)
  • mysite.com/author/1(作者 1)
  • mysite.com/book/1(作者 1 的书 1)
  • mysite.com/cart/1(作者 1 的书 1 的购物车页面)

我需要这样的网址:

mysite.com/author/1/1/cart

但我不想要嵌套模板(每个页面都是不同的,我不想在许多页面中使用相同的信息)。

有没有办法拥有那个网址?

我实际的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'});
});
4

1 回答 1

0

你有两个选择:

多个动态段

只是不要嵌套你的路线,而是有多个动态段。那是可能的:

this.route('cart', {path: '/cart/:author_id/:cart_id'});

这将为您提供如下路线:

/cart/1/A 这将呈现cart作者 1 和购物车 A 的路线

嵌套但不要将任何东西放入父路由

所以你可以拥有这个路由器:

this.route('author', {path: '/author/:author_id'}, function() {
  this.route('cart', {path: '/cart/:cart_id'});
});

现在您的问题是,如果您将作者数据放入/author路线中,它在路线上也可见author.cart。但是一个简单的解决方案是保持author路由为空,就像{{outlet}}模板一样,并将您的作者的东西放入author.index路由中。

这将为您提供如下路线:

/author/1 这将与作者 1 一起呈现author.index路线

/author/1/cart/A 这将呈现author.cart作者 1 和购物车 A 的路线

于 2017-06-25T15:17:33.650 回答