0

Like Angular UI Router is it possible to have multiple routes with same URL in Angular2? e.g following two routes:

{ path: '/home', name: 'Home', component: HomeComponent} ,
{ path: '/home', name: 'Dashboard', component: DashboardComponent}

Currently, having error in the console for conflicting routes.

Nexus23
  • 6,195
  • 9
  • 50
  • 67
  • 3
    so wich of the two components would you expect angular to render if you go to that route? – Langley Jan 11 '16 at 22:28
  • Probably last one :). Actually, I got your point. But its like UI-Router provides having multiple states having a prent linked to same URL. – Nexus23 Jan 12 '16 at 09:25
  • I think it might be easier to say what's the functionality you need or add an example of how'd you do it in ui-router – Langley Jan 12 '16 at 14:02

2 Answers2

1

You can use AuxRoute if you want ui-router style named ui-view.

https://angular.io/docs/ts/latest/api/router/AuxRoute-class.html

Also, refer this question. Is Angular 2 Auxiliary router broken?

Example: http://plnkr.co/edit/JsZbuR?p=preview

Community
  • 1
  • 1
TheKojuEffect
  • 20,103
  • 19
  • 89
  • 125
  • Thanks for your Answer @TheKojuEffect. Question was regarding multiple views pointing to same url, but each view acts like a full content page. AuxRoutes is a nice concept BTW. – Nexus23 Jan 12 '16 at 09:29
-1

You can check Angular2 - two components with the same route where possible solutions are discussed to achieve what you are after.

  1. Use *ngIf in the template to use different selectors depending on the evaluated condition.

    <home-logged-in *ngIf="authenticated()"></home-logged-in>
    <home-logged-out *ngIf="!authenticated()"></home-logged-out>
    
  2. Create custom router-outlet that will load a specific component based on evaluated condition.

  3. Redirect to a different route depending on evaluated condition (see the source http://www.captaincodeman.com/2016/03/31/angular2-route-security/)

This list is not conclusive and there might be other ways to achieve what you are looking for.

Community
  • 1
  • 1
dem00n
  • 101
  • 1
  • 6