【发布时间】:2017-09-11 20:19:16
【问题描述】:
这快把我逼疯了。 我的应用模块中有 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
为什么会这样?我想不通
编辑: 对于导航,我有一个标题组件,其中包含:
<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>
【问题讨论】:
-
您的导航如何?你在用
routerLink吗?还是.navigate?这段代码是什么样的? -
@DeborahK 我刚刚编辑了我的帖子。我用的是routerLink,但是地址栏输入url还是一样的
-
您是否尝试过打开路线跟踪以查看是否可以深入了解正在发生的事情?
-
是的,但这不是很有帮助。 “促销”路线是匹配的,但在树中它就像 AppComponent -> CustomerComponent -> CustomerSearchComponent
-
因为你有一个静态链接,为什么不像这样省略括号:
<a routerLink='/user/bob'>link to user component</a>。也许这会有所帮助?
标签: angular routing angular2-routing