簡體   English   中英

Angular4 router.navigate什么都不做

[英]Angular4 router.navigate doesn't do anything

我在系統中有基於客戶角色的條件導航。 像這樣:

this.GetQuickStartStatus()
                    .subscribe(data => {
                            if(data.isActive){
                                this.storageService.Store('isQuick', "true");
                            }
                            else{
                                this.storageService.Store('isQuick', "false");
                            }

                            if(this.storageService.Retrieve("Role") === "user"){
                                console.log("package");
                                this.router.navigate(['/packages']);
                            }

                            if(this.storageService.Retrieve("Role") === "subscriber" && this.storageService.Retrieve("isQuick") === "false"){
                                console.log("quickstart");
                                this.router.navigate(['/quickstart']);
                            }
                            console.log("nothing");
                            this.router.navigate(['']);
                    }, (error) => {
                        console.log(error);
                    });

我以新用戶登錄,該用戶應重定向到軟件包頁面,因為用戶角色為“ user。我在控制台中找到了他:

auth.service.ts:156軟件包
auth.service.ts:164沒有

意義條件被命中,但沒有執行任何操作,即路由器未導航到請求的頁面。 我檢查是否滿足所有條件,並將所有值存儲在本地存儲中。 為什么router.navigate會忽略重定向?

包的路由模塊:

@NgModule({
  imports: [
    RouterModule.forChild([
        { path: 'packages', component: PackageComponent, canActivate: [AuthGuardService] },
        { path: 'receipt', component: PackageReceiptComponent, canActivate: [AuthGuardService, RoleSubscriberGuardService] },
        { path: 'receipt/:token', component: PackageReceiptComponent, canActivate: [AuthGuardService, RoleSubscriberGuardService]}
    ])
  ],
  exports: [RouterModule]
})
export class PackageRoutingModule { }

你有this.router.navigate(['']); 在方法的末尾-每次都執行。

嘗試將此行包裝在else塊中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM