我有一個應用,匿名用戶可以在其中看到只讀視圖。當用戶單擊鏈接登錄時,我想保存當前的路由和模型,並在成功驗證後恢復它。EmberJS:登錄後返回當前路由
這是從攔截beforeModel一個過渡,然後重定向到登錄大多數的例子有一點不同。
App.ApplicationController = Ember.Controller.extend({
actions: {
logIn: function() {
this.set('previousPath', this.get('currentPath'));
this.transitionToRoute('login');
}
}
});
App.LoginController = Ember.Controller.extend({
needs: 'application',
username: '',
password: '',
actions: {
logIn: function() {
var self = this;
App.session.logIn(this.get('username'), this.get('password')).then(
function() {
var route = self.get('controllers.application.previousPath')
self.transitionToRoute(route);
});
}
}
});
這工作正常進行靜態路由,但對於動態路由模式和路由參數都將丟失。
如何捕獲當前控制器的模型或路徑參數,以便我可以恢復它們?
此示例阻止匿名用戶訪問的路由。我問的問題是如何允許匿名用戶轉移到路由,如果他們決定登錄,他們可以在登錄後返回到該路由。這與指南中的內容不完全相同。 –