Get current url in ember JS

I am trying to get the current url in emberJS, but I cannot. I'm doing it:

App.Route = Ember.Route.extend(Em.I18n.TranslateableProperties, { actions: { didTransition: function (transition) { this._super(); console.log(window.location.href); console.log(this.get('router.url')); } } }); 

I used to use didTransition because I need to know the current URL when all the elements are loaded. For example: If I am on the home page (/ home) and go to the contact page (/ contact page), I want to find out the URL / contact page.

If I use window.location.href , but not always. I thought that didTransition was called when everything else was finished, but no.

Why?

Thanks in advance

+5
source share
1 answer

didTransition does not actually have a transition argument.

Instead, you should use the afterModel method as follows:

 App.Route = Ember.Route.extend(Em.I18n.TranslateableProperties, { afterModel: function(resolvedModel, transition) { var _this = this; // keep a reference for usage in then() transition.then(function() { console.log(_this.get('router.url')); )}; } }); 

Link:

+4
source

Source: https://habr.com/ru/post/1216471/


All Articles