achan
April 18, 2015, 9:42pm
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?
Snake
April 20, 2015, 12:57pm
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.
awj
April 20, 2015, 5:01pm
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 “Example Domain ” will not).
achan
April 29, 2015, 4:11am
4
Does it differ if I’m using Ember CLI?
I tried App.__container__.lookup('router:main').get('router')
but it returns null
.
@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.
https://github.com/ember-cli/ember-export-application-global