问题
I am quite new in Angular 5 and I am trying to do my first routing. Here the situation. I have the app.component as root component and others three different component that I would like to "drive" by angular routing system, here the html code:
<div class="container-fluid">
<router-outlet></router-outlet>
</div>
<div id="main-content" class="container-fluid">
<router-outlet name="mainContentOutlet"></router-outlet>
<!--<app-xsoccer-content></app-xsoccer-content>-->
</div>
<div id="divider" class="container-fluid">
<div class="footer-divider"></div>
</div>
<div class="container-fluid">
<app-xsoccer-footer></app-xsoccer-footer>
</div>
And here my routing table:
const appRoutes: Routes = [
{ path: '', component: XsoccerHeaderComponent, children: [
{path: '', component: BrowserMainMenuComponent},
{path: 'home', component: BrowserHomeMenuComponent}
]},
{ path: '', component: XsoccerContentComponent, outlet: 'mainContentOutlet', children: [
{path: '', component: WelcomeContentComponent, outlet: 'mainContentOutlet'},
{path: 'home', component: HomeContentComponent, outlet: 'mainContentOutlet'},
]},
{path: '**', component: PagenotfoundComponent}
];
At application start the components: XsoccerHeaderComponent, BrowserMainMenuComponent, XsoccerContentComponent, WelcomeContentComponent are perfectly loaded and rendered.
But as soon as I click a login button, which I placed as BrowserMainMenuComponent's children I'm firing Router.navigate(['home']) from it, after having done some authentication logic; with the result that only BrowserHomeMenuComponent will be rendered while HomeContentComponent not.
Some of you guys can give any help please.
Thanks a lot.
回答1:
You cant have 2 blank routes on the top level of routes, try swapping the line { path: '', component: XsoccerContentComponent, outlet: 'mainContentOutlet', children: [
with something like { path: 'content', component: XsoccerContentComponent, outlet: 'mainContentOutlet', children: [
. Then call it with this.router.navigate(['/content/home'])
来源:https://stackoverflow.com/questions/50005853/angular-5-issue-with-a-named-outlet-children-component