簡體   English   中英

無法使用 -> [routerLink]=“ '/profile/ ' + currentUser.id”訪問用戶組件

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

我已經在 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>

出於兩個原因,它可能會重定向到登錄頁面:

1-您的AuthGuard失敗並重定向到登錄頁面

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