2017-11-25 6 views
0

2つのルートがあります.1つはパブリックルータで、もう1つは許可されたルータです。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を(持っている)私が行くとキャンセル次の()に、他のルータに直接行きたいが...私はリダイレクトしたくない...

私は約束の中で次のものを取り消し、ルータをリセットしますか?私の代わりに()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) 
}); 

ですそれがエラーのあるループにして無限入る(新しいリダイレクト(「ログイン」)next.cancelを返す。

EDIT

私は「this.pipeLineProviderを追加する必要があることを示しTHIS質問を見つけましたそれはまっすぐに戻って、私はコンソールでエラーを取得するパブリックルートに行くなくなり

forceReturnToPublic() { 
    this.pipelineProvider.reset(); 
    this.authService.clearIdentity(); 
    this.router.navigate("/", { replace: true, trigger: false }); 
    this.router.reset(); 
    this.aurelia.setRoot("public/public/public"); 
} 

...このように - .RESETは()」ので、私はやりました。

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) 

私はルータ-ビューを持っていclientListのナビゲーションリンクをクリックして...

どこ私はpipelineProvider.resetを配置するにはどうすればよいですか/()?

しかし、私が本当にしたいことはある...

(これは問題がある場合)どのようにきれいに他のルータに移動し、私はこのルータを停止していますか?あなたは、私は物事をしようとして続けるかのよう私はpipelineProviderは、次のステップに移動する前に完了するのに必要と考えているよう

答えて

0

は。これは...私のために働いたので、私はそうのような約束を使用:

forceReturnToPublic(): Promise<any> { 
    return Promise.resolve() 
     .then(() => this.pipelineProvider.reset()) 
     .then(() => this.authService.clearIdentity()) 
     .then(() => this.router.navigate("/", { replace: true, trigger: false })) 
     .then(() => this.router.reset()) 
     .then(() => this.aurelia.setRoot(PLATFORM.moduleName('public/public/public'))); 
} 

を..エラーなし。

関連する問題