簡體   English   中英

angular 路由器更改 url 但不加載組件/頁面

[英]angular router changes url but does not load the components / pages

我有這個導航組件

<div class="mx">
  <ul class="xv">
    <li
      *ngFor="let item of items"
      class="main-nav__item main-nav__item--{{ item.theme }}"
    >
      <a
        routerLink="{{ item.category == 'home' ? '' : item.endpoint }}"
        routerLinkActive="active"
        [routerLinkActiveOptions]="{ exact: true }"
        >{{ item.title }} </a>
    </li>
  </ul>
</div>
</nav>

在應用程序路由中

  {
    path: ":section/:layout/:layout_2/:site/:section",
    component: HomePageComponent,
  },

  {
    path: ":site/:section/:year/:month/:day/:title",
    pathMatch: "full",
    component: ArticlePageComponent

  },
 {
    path: "",
    pathMatch: "full",
    component: HomePageComponent
  },
...

所以我正在加載相同的組件但具有不同的數據,例如HomePageComponent

所以路由器只從根/主頁移動到一個部分頁面,但如果已經在部分頁面中,它不會切換到另一個部分頁面,只有 go 返回主頁

請注意,您的整個路徑是“可變的”,因為它們僅包含參數。 URL 本身只包含參數的值,但不包含參數名稱。
因此路由器無法區分路由(僅當變量的數量不同時才可能)。

例如將您的 url 更改為

path: "section/:section/layout/:layout/layout_2/:layout_2/site/:site/section/:section"

那么路由器就有機會根據“靜態”部分來區分路由。

暫無
暫無

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

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