admin管理员组文章数量:1410717
I'm trying to get the current url in emberJS but I cannot. I am doing this:
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 elements are load. For example: If I am in home(/home) page and navigate to contact page(/contact-page), I want to know the url '/contact-page'.
If I use window.location.href works, but not always. I thought that didTransition was called when everything else is finished, but not.
Why?
Thanks in advance
I'm trying to get the current url in emberJS but I cannot. I am doing this:
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 elements are load. For example: If I am in home(/home) page and navigate to contact page(/contact-page), I want to know the url '/contact-page'.
If I use window.location.href works, but not always. I thought that didTransition was called when everything else is finished, but not.
Why?
Thanks in advance
Share asked Mar 30, 2015 at 16:24 Agustin HerreraAgustin Herrera 4036 silver badges16 bronze badges 3- Is nothing logged or do you get empty logs? Just tried it in didTransition and it works fine for me. – Mårten Commented Mar 30, 2015 at 17:07
- Why do you want to know the URL? What are you going to do with it? – user663031 Commented Mar 30, 2015 at 17:08
- Hi! I need to know the URL because I have to pare with an local object – Agustin Herrera Commented Mar 31, 2015 at 6:58
1 Answer
Reset to default 5didTransition
doesn't actually have a transition
argument as your code suggests.
Instead, you should use the afterModel
method like so:
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'));
)};
}
});
Reference:
afterModel
: http://emberjs./api/classes/Ember.Route.html#method_afterModeldidTransition
: http://emberjs./api/classes/Ember.Route.html#event_didTransition
本文标签: javascriptGet Current URL in ember JSStack Overflow
版权声明:本文标题:javascript - Get Current URL in ember JS - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745018414a2637981.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论