7

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!

doorman
  • 15,707
  • 22
  • 80
  • 145

2 Answers2

6

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

{ path: '', component: HomeComponent, outlet: 'home' }
doorman
  • 15,707
  • 22
  • 80
  • 145
  • 4
    It's good that you answered your own question, but it would be better if you included a bit of explanation as to why this is the best answer. – Daniel Griscom Nov 08 '16 at 00:33
  • Related: https://stackoverflow.com/questions/51207124/angular-6-router-repeating-html https://stackoverflow.com/questions/39277700/angular-2-duplicate-header https://stackoverflow.com/questions/40198685/angular2-routing-loading-twice . I also think the app router component can be auto-generated so that most people don't encounter this issue? – mittens pair Jul 06 '18 at 22:21
  • This answer solved my problem but can you please explain why this solution works? Also, add `pathMatch: 'full'` – Verma Aman Nov 17 '20 at 18:18
2

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.

Alexander Ciesielski
  • 10,506
  • 5
  • 45
  • 66