[英]Ember router transitions to route that doesn't exist
我的ember應用程序出現問題,每當登錄頁面加載一次,我就可以正常登錄,它將我帶到正確的頁面。 但是,當我刷新登錄頁面然后登錄時,它將帶我到路由器中未設置的奇怪路由。
正確的過渡應該是login
-> authenticated.individual.info
但它需要我的路線是login
- > login.individual.info
對於導致路由器將我發送到不存在的路由的原因,我確實感到困惑,或者也許我對路由器的工作方式不太熟悉。
應用程序/ router.js
Router.map(function() {
this.route('authenticated', { path: '/:slug' }, function() {
this.resource('individual', { path: 'individual/:id' }, function() {
this.route('info');
});
});
this.route('login', { path: 'login/:slug' });
});
slug
實質上是連接到每個用戶的會員信息數據的個人短名稱。
應用程序/登錄/ route.js
import Ember from 'ember';
var bind = Ember.run.bind;
export default Ember.Route.extend({
model: function(params) {
return {'slug': params.slug};
},
actions: {
login: function(credentials) {
this.get('session').login(credentials)
.then(bind(this, 'authenticationDidSucceed'),
bind(this, 'authenticationDidFail'));
}
},
authenticationDidSucceed: function() {
var transition = this.get('controller.attemptedTransition');
var individual_id = this.get('session').individual_id;
if (transition) {
transition.retry();
} else {
this.transitionTo('individual.info', individual_id);
}
},
authenticationDidFail: function(response) {
var message = response.responseJSON.error;
this.set('controller.error', message);
},
resetController: function(controller) {
controller.setProperties({error: null, notice: null});
}
});
應用程序/登錄/ template.hbs
...
<div class='form-group'>
<button {{action 'login' model}} type='submit' class="btn btn-default form-control">Sign in</button>
</div>
...
在您的authenticationDidSucceed
方法中,您需要轉換為特定的路由名稱this.transitionTo('authenticated.individual.info')
。 與其過渡到其他路由葉,不如Ember只是在當前葉中尋找該路由。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.