Search code examples
angularuser-interfaceparentsidebar

Is it an "anti-pattern" to use the same component as parent-child (Angular)?


const routes: Routes = [
  { path: '', component: ListComponent },
  { path: ':id', component: ListComponent },
 
];

Im using the ID to pass to the sidebar, dont specifically need a child component since Im only displaying the data in the sidebar (as a pseudo child component)

Whenever you click on the item, the list doesnt disappear only the siebar either stays or disappears based on user behaviour

Can I do this without going against common practices?


Solution

  • It's completely fine.

    You can distinguish from each other with a name.

    @RouteConfig([
        { path: '/user/:id', component: User, name: 'User' },
        { path: '/user', component: User, name: 'Usernew' }
    ])
    

    Or just use optional parameter ':id?'.

    Like in a real life. Two paths can lead to the same place :)