繁体   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