Search code examples
meteoriron-router

Confusion over creating routes in Iron Router


I have a route defined as such:

Router.route('/posts/:_id/:commentsLimit?', {
    name: 'PostTemplate',
    controller: PostTemplateController
});

My question is why when I define a new route for editing the post, it is getting redirected to the route above?

Router.route('/posts/edit/:_id', {
    name: 'PostEditTemplate',
    controller: PostEditTemplateController
});

Solution

  • The url /posts/edit/anIdOfSomeKind is matched by both your routes. In these cases, Iron Router will pick the route that matches the url and was created first. So changing the order in which your routes are created will probably fix your problem.