简体   繁体   English

无法使用 -> [routerLink]=“ '/profile/ ' + currentUser.id”访问用户组件

[英]Can't reach user component using -> [routerLink]=“ '/profile/ ' + currentUser.id”

I have set in app-routing.module.ts我已经在 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'}

any uknown path word will to redirect me to the login page, but this also happening when i click on profile on the navbar button.任何未知的路径词都会将我重定向到登录页面,但是当我单击导航栏按钮上的配置文件时也会发生这种情况。

Instead of getting to the profile.componennt.html view it goes to log in. Any idea why is that happening?而不是进入 profile.componennt.html 视图,而是登录。知道为什么会这样吗?

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

For two reasons it might redirect to the login page:出于两个原因,它可能会重定向到登录页面:

1- Your AuthGuard fails and it redirects to the login page 1-您的AuthGuard失败并重定向到登录页面

2- The path is not correct in routes 2-路径中的路径不正确

{path: 'profile/:userId', component: ProfileComponent, canActivate:[AuthGuard]},
{path: '**', redirectTo: 'login'}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM