简体   繁体   中英

Meteor dynamic url explicit template finding path instead

I have a dynamic iron route with the template explicitly set, however iron router attempts to render the path instead of the template.

http://localhost:3000/blog/example-post

Couldn't find a template named "Blog:permalink" or "blog:permalink". Are you sure you defined it?

Router.route('/blog/:permalink'), {
  template: 'blogPost',
  name: 'blogPost',
  path: '/blog/:permalink',
  data: function () {
    return Blogs.findOne({ permalink: this.params.permalink, published: true });
  }
}

Router.route('blog'), {
  path: '/blog',
  waitOn: function () {
    return [
      Meteor.subscribe('blogs')
    ]
  }
}

You closed route ) without adding there the options object ( see , after ) ). That's why iron:router tries to generate template name from path:

Router.route('/blog/:permalink'), {

Should be:

Router.route('/blog/:permalink', {
  template: 'blogPost',
  name: 'blogPost',
  path: '/blog/:permalink',
  data: function () {
    return Blogs.findOne({ permalink: this.params.permalink, published: true });
  }
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM