Question

For My Application, I have maintain two states as below

  1. Login

  2. After login session: Here I need to restrict the user to click back and show alert.

So for this, In my code I have used handleURL method. It was working fine for me till Ember 1.4. But in Ember 1.5, it's shows the url got changed once I will call transitTo the same route.

App.Router.reopen({

    handleURL : function(url){
        try{
            var currentRoute = currentRoute; //get the current route here from my custom history controller class
            if(!Ember.isEmpty(_currentRoute)) {
                //based on condition call transit to the _currentRoute from my base controller class
            }
            else {
                this._super(url);
            }
        }catch(e){
            try{
            }catch(error){

            }
        }
    }
});

Can you please help on two things,

  1. How do I transit to the same route?
  2. How do manage the history hash?
Was it helpful?

Solution

1) You could use the redirect or afterModel route hook to abort a transition.

App.LoginRoute = Ember.Route.extend({

  redirect: function(model, transition) {

    if ( transition ) {

       var infos = transition.router.currentHandlerInfos;

        if (infos) {

          var lastRouteName = infos[infos.length-1].name;
          if (lastRouteName === 'home') {
            transition.abort();
          }
       }               

    }

  }
});

2) When you abort a transition triggered by the browser back button, the URL get out of sync until the next successful transition.

http://emberjs.jsbin.com/nadar/1/edit

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top