user2022581
user2022581

Reputation: 973

router or state manager or both in ember.js

The current ember documentation makes almost no mention of states. Does this mean it should not be used now, and only the router should be used which is built on top?

I am a little unclear as to how application state is to be progressed. An example of the problems I'm thinking of is going from a login screen to one of two or 3 places dependent on login success and the then logged in user's admin rights

Upvotes: 1

Views: 417

Answers (1)

Wildhoney
Wildhoney

Reputation: 4969

Thankfully there is no StateManager any more, instead we just use the router to do everything. For example, from any controller you can change to your chosen route by using:

this.transitionTo('login.invalid');

Which will take you into the LoginInvalidRoute, with the LoginInvalidController and LoginInvalidView. So if the user enters incorrect credentials, you could forward them to that route.

However, if a user logs in successfully, then you can take them to their account page:

this.transitionTo('account.default');

And if they're an administrator, to the administrator dashboard:

this.transitionTo('account.administrator');

All of this will work perfectly fine if your router is configured something like the following:

App.Router.map(function() {
    this.resource('login', function() {
        this.route('index');
        this.route('invalid');
    });
    this.resource('account', function() {
        this.route('default');
        this.route('administrator');
    })
});

Upvotes: 3

Related Questions