Repository navigation
Closed
Description
I'm submitting a...
[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
Current behavior
I need 2 named outlets for my navigation. For this I followed the official angular docs example and ended up having this:
1) Works fine
RouterModule.forRoot([
{ path: 'secondPage/:id', component: SecondPageComponent, outlet: 'contentSecond' },
{ path: 'firstPage', component: FirstPageComponent, outlet: 'contentFirst' }
], { useHash: true, enableTracing: true })Which works fine.
In my case I need to put those routes in a parent route with an Authentication Guard:
2.1) Does not work as expected
RouterModule.forRoot([
{
canActivate: [],
path: '',
children: [
{ path: 'secondPage/:id', component: SecondPageComponent, outlet: 'contentSecond' },
{ path: 'firstPage', component: FirstPageComponent, outlet: 'contentFirst' }
]
}
], { useHash: true, enableTracing: true })
// Using this to route inside the outlet
// this.router.navigate([{ outlets: { contentSecond: ['secondPage', pageNumber] } }]);Which causes this
Router Event: NavigationStart
platform-browser.es5.js:1017 NavigationStart(id: 2, url: '/(contentSecond:secondPage/1)')
platform-browser.es5.js:1017 NavigationStart {id: 2, url: "/(contentSecond:secondPage/1)"}
platform-browser.es5.js:1026
Router Event: NavigationError
platform-browser.es5.js:1017 NavigationError(id: 2, url: '/(contentSecond:secondPage/1)', error: Error: Cannot match any routes. URL Segment: 'secondPage/1')
platform-browser.es5.js:1017 NavigationError {id: 2, url: "/(contentSecond:secondPage/1)", error: Error: Cannot match any routes. URL Segment: 'secondPage/1'
at ApplyRedirects.noMatchError (http…}
core.es5.js:1020
ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'secondPage/1'
Error: Cannot match any routes. URL Segment: 'secondPage/1'
2.2) Works but feels weird since 2.1 fails
RouterModule.forRoot([
{
canActivate: [],
path: '',
children: [
{ path: 'example', component: FirstPageComponent }
]
}
], { useHash: true, enableTracing: true })
/*
Router Event: NavigationStart
platform-browser.es5.js:1017 NavigationStart(id: 2, url: '/example')
platform-browser.es5.js:1017 NavigationStart {id: 2, url: "/example"}
platform-browser.es5.js:1026
Router Event: RoutesRecognized
platform-browser.es5.js:1017 RoutesRecognized(id: 2, url: '/example', urlAfterRedirects: '/example', state: Route(url:'', path:'') { Route(url:'', path:'') { Route(url:'example', path:'example') } } )
platform-browser.es5.js:1017 RoutesRecognized {id: 2, url: "/example", urlAfterRedirects: "/example", state: RouterStateSnapshot}
*/3) This works partly but fails at the end
RouterModule.forRoot([
{
canActivate: [],
path: '',
children: [
{
path: 'home', children: [{ path: 'firstPage', component: FirstPageComponent, outlet: 'contentFirst' }]
},
{
path: 'secondPage', children: [{ path: ':id', component: SecondPageComponent, outlet: 'contentSecond' }]
}
]
}
], { useHash: true, enableTracing: true })
/*
1) Works fine
this.router.navigate([
'secondPage', {
outlets: { contentSecond: [pageNumber] }
}
]);
2) Works fine
this.router.navigate([
'home', {
outlets: { contentFirst: ['firstPage'] }
}
]);
3) Fails
this.router.navigate([
'secondPage', {
outlets: { contentSecond: [pageNumber] }
}
]);
Router Event: ResolveStart
platform-browser.es5.js:1017 ResolveStart(id: 4, url: '/secondPage/(contentSecond:1)', urlAfterRedirects: '/secondPage/(contentSecond:1)', state: Route(url:'', path:'') { Route(url:'', path:'') { Route(url:'secondPage', path:'secondPage') { Route(url:'1', path:':id') } } } )
platform-browser.es5.js:1017 ResolveStart {id: 4, url: "/secondPage/(contentSecond:1)", urlAfterRedirects: UrlTree, state: RouterStateSnapshot}
platform-browser.es5.js:1026
Router Event: ResolveEnd
platform-browser.es5.js:1017 ResolveEnd(id: 4, url: '/secondPage/(contentSecond:1)', urlAfterRedirects: '/secondPage/(contentSecond:1)', state: Route(url:'', path:'') { Route(url:'', path:'') { Route(url:'secondPage', path:'secondPage') { Route(url:'1', path:':id') } } } )
platform-browser.es5.js:1017 ResolveEnd {id: 4, url: "/secondPage/(contentSecond:1)", urlAfterRedirects: UrlTree, state: RouterStateSnapshot}
platform-browser.es5.js:1026
Router Event: NavigationError
platform-browser.es5.js:1017 NavigationError(id: 4, url: '/secondPage/(contentSecond:1)', error: Error: Cannot activate an already activated outlet)
platform-browser.es5.js:1017 NavigationError {id: 4, url: "/secondPage/(contentSecond:1)", error: Error: Cannot activate an already activated outlet
at RouterOutlet.activateWith (http://localhos…}
core.es5.js:1020
ERROR Error: Uncaught (in promise): Error: Cannot activate an already activated outlet
Error: Cannot activate an already activated outletAgain, this feels odd since routing back and forth is what I did in 1) and it worked without any errors
Expected behavior
2.1) should behave like 1) since 2.2) behaves like 1) and 3) should work, but does not
Minimal reproduction of the problem with instructions
Use code snippets from above and play around with this example
http://plnkr.co/edit/4XHwrIirGojj0fAgt5yn?p=preview
What is the motivation / use case for changing the behavior?
Make named outlets work as expected
Environment
Angular version: 4.3.1
Browser:
- [x] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
For Tooling issues:
- Node version: v8.0.0
- Platform: Windows
Others:
Edit: accidentally posted empty issue.. closed it, wrote the issue and re-opened it.
Reacted by Kim Kern, brando.wang, lukaszlubinski, Dmitri Maltsev, Olaf Kasper, patachon, Forrest, Jack, Daniel Wegener, Muhammad Hasan and 41 more
Activity
[-]Routing: Named outlets do not work properly with route guards [/-][+]Routing: Named outlets do not work properly as child routes[/+]BrsJsk commentedon Aug 22, 2017
Same problem. All my routes are child routes. I can navigate them to the default page, but not to the named outlet.
bennadel commentedon Oct 4, 2017
I believe I am running into the same issue. I have a named outlet that is a child of a path-less component. I have a Plunkr for it. The primary outlet seems to work (Layout A / B); but, the sibling named-outlet is breaking with an unexpected error message,
Error: Cannot match any routes. URL Segment: 'layout-a'.Plunkr: https://plnkr.co/edit/3HLVIYDdxycups61L8TA
ramzgt commentedon Nov 13, 2017
Anyone figure out this issue? I am running into the same thing.
abattoiry commentedon Nov 30, 2017
same problem, child empty-path named route cant override parent's. For example:
{ path: '', component: HeaderComponent, outlet: 'header', },
{
path: 'about',
children: [
{ path: '', component: AboutComponent },
{ path: '', component: EmptyHeaderComponent, outlet: 'header', },
]
},
which causes error: Cannot activate an already activated outlet.
jwuliger commentedon Jan 22, 2018
I can report this happening to me as well. I am using Angular 6.0.0-beta.0
nickwinger commentedon Mar 14, 2018
This is a major issue and should not be in the Backlog...
RobViableIs commentedon Mar 15, 2018
Has anyone found any solution?
13 remaining items
gotwig commentedon Aug 6, 2019
for 2 years -are you kidding me?
loroz commentedon Sep 5, 2019
The problem is tied to the fact that the RouterModule's 'routes' is configured with an empty path:
Give the root path a name:
Then adjust your links in AppComponent's template by adding 'main' to the links:
After making those changes, your StackBlitz example works properly:
eddietisma commentedon Oct 24, 2019
+1
Same issue with Angular 8.2.8
DaSchTour commentedon Jan 27, 2020
Seams still not being fixed with angular 9.
Just posting to ensure that this is not closed like #10726
LordRembo commentedon Feb 5, 2020
Same issue as #12740 as well I think? That one was closed but still doesn't work
I documented the 2 workarounds in this StackOverflow post in case anyone else is stuck on it:
https://stackoverflow.com/questions/41054333/angular-2-how-to-redirect-route-to-child-route-with-named-outlet/60072126#60072126
nt-michael commentedon Mar 3, 2020
I managed to bypass this by placing the auxiliary outlet right inside the child component then creating an empty child route and it works.
Here's my code
for instance my
path: 'home', component:HomeComponentis as follows:
hope my approach helps ;)
atscott commentedon May 27, 2020
Duplicate of #10726. That issue has been re-opened, as the fix was reverted.
SamOrozco commentedon Jun 14, 2020
@albanx The second example you gave worked for me.
angular-automatic-lock-bot commentedon Jul 15, 2020
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.