Search code examples
javascriptember.jsurl-routing

TransitionTo child path where parent has dynamic segment


As the title suggests I'm trying to transitionTo a child path from a action. The problem is that Ember says that it can't find any paths with that name. Looking at the Ember docs I've no idea what I'm doing wrong here. I'm hoping someone here might have the expertise to help me out.

Ember Error:

Uncaught Error: Assertion Failed: The route post.comments was not found

Application route definition:

this.resource('post', { path: 'post/:post_id' }, function () {
    this.resource('comments');
});

The transitionTo in the action:

route.transitionTo('post.comments', post_id);

Solution

  • Route post.comments doesn't exist because you define comments as resource instead of route. I guess this should work:

    this.resource('post', { path: 'post/:post_id' }, function () {
        this.route('comments');
    });
    
    route.transitionTo('post.comments', post_id);
    

    However if you really need to declare comments as resource, use:

    route.transitionTo('comments', post_id);