[英]Cannot navigate to child routes after returning to parent component from deeply nested link (Angular4)
I have set up a plunk to demonstrate the problem: 我已经设置了一个插件来演示这个问题:
https://plnkr.co/edit/BSxXBkXUFy3FcJTOf84F?p=preview https://plnkr.co/edit/BSxXBkXUFy3FcJTOf84F?p=preview
Here is the navigation flow => 这是导航流程=>
For some reason, After following the steps outlined above I will no longer be able to navigate anywhere and the app will crash. 出于某种原因,按照上面列出的步骤后,我将无法再在任何地方导航,应用程序将崩溃。
Here is the necessary code: 这是必要的代码:
PARENT 家长
<div *ngIf="router.url != '/parent/child2'">
<ul>
<li><a routerLinkActive="active" routerLink="child1">Child1</a></li>
</ul>
<router-outlet></router-outlet>
</div>
<div *ngIf="router.url == '/parent/child2'">
<router-outlet></router-outlet>
</div>
CHILD1 CHILD1
<div>
<a routerLinkActive="active" routerLink="../child2">Child2</a>
</div>
ROUTING 路由
const appRoutes: Routes = [
{path: '', redirectTo: '/parent/child1', pathMatch: 'full'},
{
path: 'parent',
component: ParentComponent,
children: [
{path: 'child1', component: Child1Component},
{path: 'child2', component: Child2Component}
]
}
];
When running this example locally (through the CLI) I get this error: (which for some reason is not appearing on the plunk) 在本地运行此示例(通过CLI)时,我收到此错误:(由于某种原因未出现在plunk上)
ERROR Error: Uncaught (in promise): Error: Cannot activate an already activated outlet
Error: Cannot activate an already activated outlet
at RouterOutlet.webpackJsonp.../../../router/@angular/router.es5.js.RouterOutlet.activateWith (router.es5.js:5430)
at ActivateRoutes.webpackJsonp.../../../router/@angular/router.es5.js.ActivateRoutes.activateRoutes (router.es5.js:4578)
at router.es5.js:4529
at Array.forEach (<anonymous>)
at ActivateRoutes.webpackJsonp.../../../router/@angular/router.es5.js.ActivateRoutes.activateChildRoutes (router.es5.js:4529)
at ActivateRoutes.webpackJsonp.../../../router/@angular/router.es5.js.ActivateRoutes.activateRoutes (router.es5.js:4546)
at router.es5.js:4529
at Array.forEach (<anonymous>)
at ActivateRoutes.webpackJsonp.../../../router/@angular/router.es5.js.ActivateRoutes.activateChildRoutes (router.es5.js:4529)
at ActivateRoutes.webpackJsonp.../../../router/@angular/router.es5.js.ActivateRoutes.activate (router.es5.js:4422)
at RouterOutlet.webpackJsonp.../../../router/@angular/router.es5.js.RouterOutlet.activateWith (router.es5.js:5430)
at ActivateRoutes.webpackJsonp.../../../router/@angular/router.es5.js.ActivateRoutes.activateRoutes (router.es5.js:4578)
at router.es5.js:4529
at Array.forEach (<anonymous>)
at ActivateRoutes.webpackJsonp.../../../router/@angular/router.es5.js.ActivateRoutes.activateChildRoutes (router.es5.js:4529)
at ActivateRoutes.webpackJsonp.../../../router/@angular/router.es5.js.ActivateRoutes.activateRoutes (router.es5.js:4546)
at router.es5.js:4529
at Array.forEach (<anonymous>)
at ActivateRoutes.webpackJsonp.../../../router/@angular/router.es5.js.ActivateRoutes.activateChildRoutes (router.es5.js:4529)
at ActivateRoutes.webpackJsonp.../../../router/@angular/router.es5.js.ActivateRoutes.activate (router.es5.js:4422)
at resolvePromise (zone.js:770)
at resolvePromise (zone.js:741)
at zone.js:818
at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:424)
at Object.onInvokeTask (core.es5.js:3924)
at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:423)
at Zone.webpackJsonp.../../../../zone.js/dist/zone.js.Zone.runTask (zone.js:191)
at drainMicroTaskQueue (zone.js:584)
at HTMLAnchorElement.ZoneTask.invoke (zone.js:490)
I'm not sure what is causing the crash? 我不确定导致撞车的原因是什么?
I hope the problem is clear! 我希望问题很清楚! Please let me know if you need any more information. 如果您需要更多信息,请与我们联系。
Have you tried changing the if condition so that the router-outlet is not included in it? 您是否尝试更改if条件以使路由器插座不包含在其中? Something like this: 像这样的东西:
<div *ngIf="router.url != '/parent/child2'">
<ul>
<li><a routerLinkActive="active" routerLink="child1">Child1</a></li>
</ul>
</div>
<router-outlet></router-outlet>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.