簡體   English   中英

路由器導航在 Angular 中不起作用

[英]Router navigate is not working in Angular

我在我的 angular 項目中設置了路由,下面是我在根模塊中的路由

const appRoutes: Routes = [
  { path: '', component: LoginComponent },
  { path: 'dashboard', canActivate: [AuthGuard], component: DashboardComponent }
];

在我的app.component.ts我有我的<router-outlet></router-outlet>

在我的登錄頁面中,我有一個 function 導航到http://localhost:4200/dashboard一旦成功登錄

登錄組件.ts

login() {
....
this.router.navigate(['dashboard'], {relativeTo: this.route});
....
}

現在的問題是,當我在瀏覽器中執行ng serve並打開localhost:4200時,我將無法登錄。 只有在重新加載頁面后,即localhost:4200我才能登錄。

是什么阻止我在這里登錄而不重新加載? 請告訴我:)

我認為當您嘗試導航到路由“儀表板”時,路由保護會拒絕您的操作,因為可能不是有效的令牌或 AuthGuard 中的某些邏輯。 您必須檢查您的 AuthGuard

暫無
暫無

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

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