我有兩個途徑 - 一個是公共路由器,另一個是授權的路由器。如何重定向到另一個路由器從AuthorizedStep
在我的授權路由器中,我有一個authorizeStep。
authorizedStep檢查localStorage中是否存在令牌,如果是則返回next()。
但是,如果它找不到令牌,它應該停止並跳出回到公用路由器。
我無法停止授權的步驟,而是轉到公共路由器。
我:
run(navigationInstruction: NavigationInstruction, next: Next): Promise<any> {
return Promise.resolve()
.then(() => this.checkSessionExists(navigationInstruction, next)
.then(result => result || next())
);
}
checkSessionExists(navigationInstruction: NavigationInstruction, next: Next) {
const session = this.authService.getIdentity();
if (!session) {
// HOW DO I CANCEL THE NEXT HERE AND GO TO THE PUBLIC ROUTER?
return next.cancel(new Redirect('login'))
}
return next()
}
forceReturnToPublic() {
this.authService.clearIdentity();
this.router.navigate("/", { replace: true, trigger: false });
this.router.reset();
this.aurelia.setRoot("public/public/public");
}
我具備的功能forceReturnToPublic(),但是我想去並取消下一個(),然後直接去其他路由器......我不想重定向..
如何取消承諾中的下一步並重置路由器?
這裏是我的boot.ts應該踢回給公衆,但我不知道如何跳出乾淨的承諾...
// After starting the aurelia, we can request the AuthService directly
// from the DI container on the aurelia object. We can then set the
// correct root by querying the AuthService's checkJWTStatus() method
// to determine if the JWT exists and is valid.
aurelia.start().then(() => {
var auth = aurelia.container.get(AuthService);
let root: string = auth.checkJWTStatus() ? PLATFORM.moduleName('app/app/app') : PLATFORM.moduleName('public/public/public');
aurelia.setRoot(root, document.body)
});
如果我放在forceReturnToPublic()代替的返回next.cancel(新重定向(「登錄」),它進入與錯誤無限循環。
編輯
我發現THIS問題,這表明我要補充「this.pipeLineProvider .reset()「所以我做了 - 像這樣...
forceReturnToPublic() {
this.pipelineProvider.reset();
this.authService.clearIdentity();
this.router.navigate("/", { replace: true, trigger: false });
this.router.reset();
this.aurelia.setRoot("public/public/public");
}
雖然它直接回到公共路線,我在控制檯中得到一個錯誤。
aurelia-logging-console.js:47 ERROR [app-router] Error: There was no router-view found in the view for ../components/clients/clientList/clientList.
at _loop (aurelia-router.js:281)
at NavigationInstruction._commitChanges (aurelia-router.js:307)
at CommitChangesStep.run (aurelia-router.js:143)
at next (aurelia-router.js:112)
at iterate (aurelia-router.js:1272)
at processActivatable (aurelia-router.js:1275)
at ActivateNextStep.run (aurelia-router.js:1161)
at next (aurelia-router.js:112)
at iterate (aurelia-router.js:1191)
at processDeactivatable (aurelia-router.js:1194)
我點擊客戶端列表導航鏈接裏面確實有一個路由器視圖上..
如何/我在哪裏放置pipelineProvider.reset()? (如果這是問題)
但我真正想要的是......
如何停止該路由器和乾淨移動到另一臺路由器?