1

I have a component which renders some set of child routes but the layout is different - Can we use same path name for both layouts as below

{
    path: '',
    component: LandingComponent,
    children: [
      { path: '', component: LandingpageComponent },
      { path: 'landingpage', component: LandingpageComponent },
    ]
  },
  {
    path: '',
    component: DashboardComponent,
    children: [
      { path: 'patients', component: PatientsComponent },
      { path: 'endrolPatient', component: ProfileComponent },
      { path: 'endrolPatient/:id', component: ProfileComponent },

    ]
  }

In the above example the path names are same - when I run the application I can see the output - how does angular works with this kind off routing.

1 Answer 1

1

Yes, you can!

Basically, as per the Angular router structure, you can have multiple router path for the same component.

Say you want to use your component A with two links as following -

abc.com/first
abc.com/second

Here, in that case, you can use the same component.

Sign up to request clarification or add additional context in comments.

2 Comments

path name can be same ? In my case i have two path with empty name - But angular picks up the correct child how does the routing groups itself ?
yes, path name can be the same but on the same level, but again why anybody does this. Doesn't make any sense. In your case there is parent and child concept is there. also, you must have the outlet in the parent route as well so it will show first empty/defauly child as your route.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.