我想要在EmberJS中获取当前的URL,但是我无法实现。我正在尝试以下方法:
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'));
}
}
});
我曾经使用 didTransition,因为我需要在所有元素加载完毕时知道当前URL。例如:
如果我在主页(/home)并导航到联系页面(/contact-page),我想知道URL '/contact-page'。
如果我使用 window.location.href,虽然可以工作,但不总是有效。我认为 didTransition 是在其他所有事情都完成后调用的,但这并不总是正确的。
为什么?
提前感谢。