Angular 路由器总是重定向到同一个模块

Angular router always redirecting to the same module

这让我发疯。 我的应用程序模块中有 3 条简单的路线:

routes: Routes = [
    { path: '', redirectTo: '/customers', pathMatch: 'full' },
    { path: 'customers', loadChildren: './components/customer#CustomerModule' },
    { path: 'promotions', loadChildren: './components/promotion#PromotionModule'}
];

在我的客户模块中,我定义了这些路线:

routes: Routes = [
    {
        path: '', component: CustomerComponent, children: [
            { path: '', component: CustomerSearchComponent },
            { path: ':id', component: CustomerDetailComponent }
    ]}
];

在我的推广模块中:

routes: Routes = [
    { path: '', component: PromotionComponent },
    { path: 'new', component: PromotionNewComponent }
];

我的 AppComponent 和 CustomerComponent 中有一个 <router-outlet></router-outlet>。 问题是,当我去路线 /promotions 时,我仍然被重定向到 CustomerModule -> CustomerComponent -> CustomerSearch

为什么会这样?我想不通

编辑: 对于导航,我有一个 header 组件,其中包含:

<ul class="nav navbar-nav">
            <li>
                <a [routerLink]="['./customers']"
                   routerLinkActive="active" [routerLinkActiveOptions]="{exact: true}">
                    Customers
                </a>
            </li>
            <li>
                <a [routerLink]="['./promotions']"
                   routerLinkActive="active" [routerLinkActiveOptions]="{exact: true}">
                    Promotions
                </a>
            </li>
        </ul>

应用组件是这样的:

<app-header></app-header>

<main class="container">
  <router-outlet></router-outlet>
</main>

我认为您需要指定完整的路由,即使在功能模块路由中也是如此。

发生的事情是它进入您的 Customer 路由并找到路径 '' + '' 并登陆 CustomerSearchComponent。

尝试将客户路由的基本路径更改为 'customer' 而不是 '',并将促销路由中的路径更改为 'promotion' 和 'promotion/new'