簡體   English   中英

為什么 Angular routerLink(沒有前導斜杠)在導航回空路徑時被破壞?

[英]Why is Angular routerLink (without leading slash) broken when navigating back to empty path?

讓我們以這個基本的導航樹為例:

  • 基本的
    • 次要的
      • 深的

看看我的Stackblitz 項目

我的路線是

const routes: Routes = [
  {
    path: "",
    component: PageParentComponent,
    children: [
      {
        path: "",
        component: PageChildPrimaryComponent
      },
      {
        path: "secondary",
        component: PageChildSecondaryComponent
      },
      {
        path: "secondary/deep",
        component: PageDeepComponent
      }
    ]
  }
];

使用<a routerLink=".."> ,我可以成功導航上一層,並使用<a routerLink="../..">兩層。 但是,當我使用雙點從任何更深的頁面返回“主”頁面時,任何不以斜杠開頭的routerLink都會搞砸; URL 的根部分( https://angular-ukxb4a.stackblitz.io/localhost:4200/ ,在本地運行時)替換為%28 當我使用<a routerLink="/"> (斜線而不是雙點)時,一切都很好。

為什么會這樣?

你要去的網址是

https://angular-ukxb4a.stackblitz.io/secondary

不是

https://%28secondary%29/

起始斜杠將路徑附加到您現有的路徑。 我希望這能幫到您。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM