Search code examples
dynamicember.jsstateember-router

Ember-Router: create route dynamically


I am trying to dynamically create a route to my router. I know there is serialize for doing this, but it appears to only accept a finite amount of parameters. For example, I need to be able to build a route that could be /:a or /:a/:b/:c.

My question is, is there a way to get what the original path request was?

I will need to:

  • get the original path
  • pause the router so an ajax call can be made to retrieve path info.
  • request from the server the path and return the module if it exists (I have that much set up).
  • If path exists, create the route and move the application into that state.

Solution

  • You can access the requested location via the router's location property. You could then split the returned string and access the different parameters.

    locationString = App.router.get('location.location.hash')
    // something like "/1/2"
    params = locationString.split(/\//)
    param1 = params[1] // => "1"
    param2 = params[2] // => "2"