TransitionTo无法正常工作

时间:2013-12-04 04:32:15

标签: javascript ember.js

我想创建一个转换,比如,如果有人去索引或/ profile-details,它将被重定向到/ profile-details / preview。这是我的地图和重定向代码:

UserProfileApp.Router.map(function () {

                this.resource('profile', { path: '/' }, function () {

                    this.resource("personal", { path: "personal-details" }, function () {
                        this.route("preview", { path: "preview" });
                        this.route("edit", { path: "edit" });
                    });

                    this.route("loyalty", { path: "loyalty-membership" });

                    this.resource("passengers", { path: "passengers" }, function () {
                        this.route("new", { path: "new" });
                        this.route("passenger", { path: ":passenger_id" });
                    });

                    this.route("password", { path: "password" });
                });

            });

            UserProfileApp.ProfileRoute = Ember.Route.extend({
                beforeModel: function () {
                    this.transitionTo('personal');
                }
            });

            UserProfileApp.PersonalRoute = Ember.Route.extend({
                beforeModel: function () {
                    this.transitionTo('personal.preview');
                }
            });

如果我删除任何transitionTo,它会相应地工作,但是两个transitionTo都没有工作

2 个答案:

答案 0 :(得分:1)

@Edu的附录: 您还可以传入要传输的ID:

this.transitionTo('personal', eventualId);

答案 1 :(得分:0)

你试过这个吗?

        UserProfileApp.ProfileRoute = Ember.Route.extend({
            beforeModel: function () {
                this.transitionTo('personal');
            }
        });

        UserProfileApp.PersonalRoute = Ember.Route.extend({
            beforeModel: function () {
                this.transitionTo('preview');
            }
        });
祝你好运