刷新 emberjs 时重定向
Getting redirected when refreshed emberjs
我的router.js
是这样的:
// router.js
this.route('cards', function() {
this.route('all');
this.route('card', {path: '/:card_id'}, function() {
this.route('edit');
});
this.route('new');
});
现在,假设我在这个 link: /cards/1
里面。当我刷新此页面时,我转到路线 /cards/all
.
我正在从 /cards
重定向到 /cards/all
:
// cards.js
beforeModel() {
this.transitionTo('cards.all');
}
为什么我在 /cards/1
中刷新时被重定向到 /cards/all
?
你被转换到 /cards/all
,因为路由 /cards/:card_id
嵌套在 /cards
路由中,所以当你进入 /cards/:card_id
路由时,执行顺序是:
cards
路线 (beforeModel, model, ...)
cards/:id
路线(beforeModel, model, ...)
但是在 cards route beforeModel 中你正在过渡到 cards.all
,这就是重定向的原因。
我的router.js
是这样的:
// router.js
this.route('cards', function() {
this.route('all');
this.route('card', {path: '/:card_id'}, function() {
this.route('edit');
});
this.route('new');
});
现在,假设我在这个 link: /cards/1
里面。当我刷新此页面时,我转到路线 /cards/all
.
我正在从 /cards
重定向到 /cards/all
:
// cards.js
beforeModel() {
this.transitionTo('cards.all');
}
为什么我在 /cards/1
中刷新时被重定向到 /cards/all
?
你被转换到 /cards/all
,因为路由 /cards/:card_id
嵌套在 /cards
路由中,所以当你进入 /cards/:card_id
路由时,执行顺序是:
cards
路线 (beforeModel, model, ...)cards/:id
路线(beforeModel, model, ...)
但是在 cards route beforeModel 中你正在过渡到 cards.all
,这就是重定向的原因。