Iron-router nested routes with multiple parameters

亡梦爱人 提交于 2019-12-04 12:26:04

I recommend to save slug inside article document. App can generate slug from title using Underscore.String.slugify function (https://github.com/epeli/underscore.string) when user add/edit article.

Route with multiple params are valid:

this.route('showArticle', {
  path: '/:siteName/:articleSlug'),
  ...
  data: function(){

     viewData = {
       title: Articles.findOne({slug: this.params.articleSlug}).title,
       site:  Sites.findOne({name: this.params.siteName})
     }
     return viewData;
  }
});

Finally I've solved this problem: I've followed suggestions and added friendlyTitle field to object from Articles collection that contains parsed article title (without special characters).

And this is my route:

this.route('showArticle', {
    path: '/:site/:friendlyTitle',
    layoutTemplate: 'artLayout',
    data: function(){
        return Articles.findOne({friendlyTitle: this.params.friendlyTitle});
    }
});

:site field contains name of the object from Sites collection that has this article assigned (when creating new article I can assing/publish it to/on the specific site).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!