Angular 路由器导航未在角度模式下工作

Angular 路由器导航未在角度模式下工作,angular,angular-routing,angular-router,Angular,Angular Routing,Angular Router,我已经在我的angular项目中设置了路由,下面是我在根模块中的路由 const appRoutes: Routes = [ { path: '', component: LoginComponent }, { path: 'dashboard', canActivate: [AuthGuard], component: DashboardComponent } ]; 在我的app.component.ts中,我有我的位置 在我的登录页面中,我有一个导航到http://localhos

我已经在我的angular项目中设置了路由,下面是我在根模块中的路由

const appRoutes: Routes = [
  { path: '', component: LoginComponent },
  { path: 'dashboard', canActivate: [AuthGuard], component: DashboardComponent }
];
在我的
app.component.ts
中,我有我的
位置

在我的登录页面中,我有一个导航到
http://localhost:4200/dashboard
一旦成功登录

login.component.ts

login() {
....
this.router.navigate(['dashboard'], {relativeTo: this.route});
....
}
现在的问题是,当我使用
ng-serve
并在浏览器中打开
localhost:4200
时,我将无法登录。只有在重新加载页面后,即,
localhost:4200
我才能登录


是什么阻止我在不重新加载的情况下登录?请让我知道:)

我认为当您尝试导航到路由“仪表板”时,路由守卫会拒绝您的操作,因为可能不是AuthGuard中的有效令牌或某些逻辑。你必须检查你的警卫