Reputation: 11
I have found many routing issues here on Stack Overflow, but not an answer to my question. After user logs in, user gets routed to a parent that has child route:
{
path: '',
component: LoginComponent,
},
{
path: 'parent',
component: ParentComponent,
children: [
{
// without this routing does not work
path: '',
redirectTo: 'parent'
},
{
path: 'child',
component: ChildComponent,
},
]
},
//... more routes
My problem is that without the following mentioned in children
:
path: '',
redirectTo: 'parent'
User doesn't get routed to parent route at all from login page. But this also messes with my url and instead of just
localhost:3000/parent
I get localhost:3000/parent/parent
. That still displays the correct component. But when user navigates elsewhere, there is error:
Cannot match any routes: 'something/something'
How can I fix this, thank you?
Upvotes: 1
Views: 763
Reputation: 73377
The problem with your url is probably caused when you navigate to your parent-component, and if the path is ''
, meaning localhost:3000/parent
in your case,
then you redirectTo
parent
again, therefore causes localhost:3000/parent/parent
Try just to remove the redirectTo: 'parent'
and see what happens!
Upvotes: 1