4
我已經向我的路由器添加了授權管道步驟。一切正常,但是當我使用Redirect
類將用戶指向登錄頁面時,它將URL作爲其參數。如果我使用Router.navigateToRoute()
,我寧願傳入路由名稱。這可能嗎?使用Aurelia重定向類
@inject(AuthService)
class AuthorizeStep {
constructor (authService) {
this.authService = authService;
}
run (navigationInstruction, next) {
if (navigationInstruction.getAllInstructions().some(i => i.config.auth)) {
if (!this.authService.isLoggedIn) {
return next.cancel(new Redirect('url-to-login-page')); // Would prefer to use the name of route; 'login', instead.
}
}
return next();
}
}