Reputation: 307
I want to call a function when their is a change in URL.
In newer versions of Ember, we can do this by observing currentPath
.
In this version, I tried this:
Ember.Route.reopen({
enter: function(router) {
console.log('change in URL and need to be called once per change in URL');
}
});
Since there are nested routes, so this method was called mutiple times.
Upvotes: 0
Views: 150
Reputation: 19128
If you are using Ember.HashLocation
you can do this, observing lastSetURL
property:
window.App = Ember.Application.create({
...
urlChanged: function(a,b,c,d) {
var url = this.get('router.location.lastSetURL');
if (!Ember.none(url)) {
alert(url);
}
}.observes('router.location.lastSetURL'),
...
});
Here is a example of this working http://jsfiddle.net/marciojunior/ba4hJ/
Upvotes: 2