mardi 30 juin 2015

Ember - get target url of transition

I am creating an error hook in my Ember.js app to redirect you to the auth service if you are not allowed to view certain content (in other words, if the server returns a 401).

It looks like this:

Ember.Route = Ember.Route.extend({
  error: function(error, transition){
    if (error.status === 401) {
      window.location.replace("http://ift.tt/1RPWWyz");
    }
  }

Our auth api works as follows: If you send it a parameter called target (which is a url), it will redirect you back to that target url after you've logged in.

So I want to somehow get the URL of the route the Ember app was trying to transition to.

Then my code will end up something like this

Ember.Route = Ember.Route.extend({
  error: function(error, transition){
    if (error.status === 401) {
      var target = // Your answer here
      window.location.replace("http://ift.tt/1RPWWyD" + encodeURIComponent(target));
    }
  }




Aucun commentaire:

Enregistrer un commentaire