Search code examples
ember.jsember-router

replaceRoute with an object id


I want to use the replaceRoute in an ember controller but need to pass an object id. Something along the lines of:

this.replaceRoute('projects.edit', 4)

Is that possible at all or should it be done differently? It's going to the route I tell it to but with an object id of undefined.


Solution

  • Is that possible at all or should it be done differently?

    replaceRoute expects to be passed the route's context, not an id. You can use the id to locate the context, for example:

    this.replaceRoute('projects.edit', App.Project.find(4));
    

    Here is a jsfiddle demonstrating how this approach using the fixture adapter

    http://jsfiddle.net/mgrassotti/mhyjG/1/