0

我已经在 app-routing.module.ts 中设置了

{path: 'profile:/userId', component: ProfileComponent, canActivate:[AuthGuard]},
// In case the address doesn't match our paths ,redirects to login
{path: '**', redirectTo: 'login'}

任何未知的路径词都会将我重定向到登录页面,但是当我单击导航栏按钮上的配置文件时也会发生这种情况。

而不是进入 profile.componennt.html 视图,而是登录。知道为什么会这样吗?

 <a [routerLink]="'/profile/' + currentUser.id" class="nav-link">Profile</a>
4

1 回答 1

1

出于两个原因,它可能会重定向到登录页面:

1-您AuthGuard失败并重定向到登录页面

2-路径中的路径不正确

{path: 'profile/:userId', component: ProfileComponent, canActivate:[AuthGuard]},
{path: '**', redirectTo: 'login'}
于 2019-09-27T19:11:34.700 回答