Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Named router outlet not working

Tags:

angular

I am trying to use named outlets. In app.routes I have the following path.

{ path: 'home', component: HomeComponent, outlet: 'home' }

app.component.html contains

 <router-outlet name="home"></router-outlet>
 <router-outlet></router-outlet>

The home outlet never displays the home component. If I remove the outlet name from the router path the unnamed outlet will show the HomeComponent. I am using the latest Angular 2. Any idea why the named outlet doesn't work?

[UPDATE] Here is working plunkr, you only need to look into app.comoponent.ts . If you click the links to Crisis Center or Hereos I would expect the navigated components to appear inside the red named outlet zone?

https://plnkr.co/edit/l2Li0sLbbEIRZCppRlvF?p=preview

Thanks for your help!

like image 885
doorman Avatar asked Oct 12 '16 12:10

doorman


2 Answers

So the problem was that I had to leave the path property empty like this..

{ path: '', component: HomeComponent, outlet: 'home' }
like image 102
doorman Avatar answered Sep 17 '22 11:09

doorman


Router outlets in Angular 2 are defined as <router-outlet>. Also you should try quotes instead of apostrophes in your HTML template.

In general, if you only have one outlet in your template it is best practice not to give them a name.

like image 34
Alexander Ciesielski Avatar answered Sep 20 '22 11:09

Alexander Ciesielski