Ember.js: transitionTo route, then to dynamic segment

前端 未结 5 1226
北荒
北荒 2021-02-01 07:45

I have a Router set up with accounts, and account/:account_id options. When the user lands on the index page of my app I transition them to the accounts route.

S         


        
5条回答
  •  猫巷女王i
    2021-02-01 08:12

    I put together others' answers and some fiddling and came out with this answer:

    define your routes like:

    this.resource('accounts', function () {
        this.route('account', {path: '/:account_id'});
    });
    

    redirect:

    this.transitionTo('accounts.account', accountObj);
    

    But if you are loading from server, you need the accountObj object loaded before redirect:

    var accountObj = App.Account.find(1);
    accountObj.one('didLoad', this, function () {
        this.transitionTo('accounts.account', accountObj);
    });
    

    I set up this fiddle with complete example

提交回复
热议问题