Routes redirecting without transition history saving



Trying to make an authorization in a server-like-app approach and cant cope with transition.

I have the configuration similar to this topic author. {
 this.route('login', { path: '/' });

App.HomeRoute = Ember.Route.extend({
redirect: function() {
    if (!App.User.loggedIn) {

When I am actually logged in and trying to access / route, it must redirect me to another default route (let it be ‘home’ to clarify). I can do it using transitionTo in the same way

App.LoginRoute = Ember.Route.extend({
redirect: function() {
    if (App.User.loggedIn) {

The problem is that after this I can press the “back” button and it will transit me to the login route again. Its okay because I will be redirected to home immediately but it seems like a dead loop.

User never could back to the page he came from. So scaring…


You can use the replaceWith method on Routes. See the documentation here:

It’s effectively the same as transitionTo but won’t add an item to the browser’s history.



Works great for me! Thank you! This aspect is not reflects in guides well enough.