ember.js - Detect URL change and grab URL in EmberJS (using Discourse) -


i'm using discourse (http://www.discourse.org/), built on emberjs, , trying observe time url changes, e.g. when opening new topic. i've seen answer observing currentpath, example here: detect route transitions in emberjs 1.0.0-pre.4

app.applicationcontroller = ember.controller.extend({    routechanged: function(){     // currentpath has changed;   }.observes('currentpath'); }); 

but i'm trying detect any url change, not path change. mentioned in comments answer:

this observer doesn't fire when transitioning example /pages/1 /pages/2 because path staying same: pages.page.index

what i'd detect aforementioned transitions don't triggered observes('currentpath'). along lines, if this.get('currentpath'); inside of function, topic.fromparams interested in url path e.g. /t/this-is-my-url-slug.

to put simply, i'd detect when app goes from:

/t/this-is-my-url-slug 

to

/t/another-url-slug 

and able capture path: /t/another-url-slug

sorry i'm bit of ember n00b , experience through discourse. ideas?

you don't need ember-specific this. depending on whether using hash or pushstate, can use...

$(window).on('hashchange', function(){   console.log("hash url " + location.hash.substr(1));   // stuff }); 

or

$(window).on('popstate', function(e) {   console.log("hash url " + window.location.pathname);   // stuff }); 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -