Any way to take a string URL and extract the route parameters from it?


#1

Is there an equivalent of Rails.application.routes.recognize_path in Ember? #recognize_path would take a url and break it down like so:

> Rails.application.routes.recognize_path('/posts/234/this-is-my-post')
=> {:action=>"show", :controller=>"posts", :post_id=>"234", :slug=>"this-is-my-post"}

Is there anything similar to this in Ember?


#2

I’m stuck on Ember 1.4.0 so not sure if this will work, it kinda gives you what you need I think.

App.__container__.lookup('router:main').get('router').recognizer.recognize('register')

Worth looking at https://github.com/tildeio/route-recognizer is well.


#3

Just to confirm, the above code does still work as of 1.10. Also as an FYI: the route recognizer doesn’t handle anything but the plain Ember path. (e.g. “/posts/123” will work, but “#/posts/123” and “http://www.example.com/#/posts/123” will not).


#4

Does it differ if I’m using Ember CLI?

I tried App.__container__.lookup('router:main').get('router') but it returns null.


#5

@achan note that because of the way ember cli works with modules there is no global App variable hanging off of window.

You might want to check out this addon if you would like to debug that way.