I have a component that has some child routes
which are defined on this file : ProductUsageRoutes
and on my component I have a button that should navigate the user to another component with the path 'new' , but it's not working. it shows the correct path on the url when I click the button but it doesn't go anywhere nor show any errors on console
#Child route not working
37 messages · Page 1 of 1 (latest)
g!badeyes @silent junco
@silent junco Please do not post pictures of code (especially photos of a physical screen) as they are difficult to read and difficult to correct (as you cannot copy code from a screenshot to modify it).
Does the other path with the same component work?
Sorry I didn't know
it does not!
Then the problem should be with the component.
Can you copy paste its html and ts code?
I think the problem it's not with the component since I tried with another component and it doesn't work either
😦
it simply doesn't navigate to anywhere
The starting route is protected by some guard, or is the first one in the picture you showed?
do you mean this one? yeah it has a guard but I tested removing the guard and it's not working either, so I don't think that's the problem
😔
Try to get rid of that component property, considering that you already bound it in the first child.
And I doubt you want both the editing form both the list components rendered together.
From the route you showed in the last picture
If you had copy/pasted code, I had directly posted the changes.
Sorry, I see. I can't remove it there since that component can be accesed from another screen so it needs a path
It already has the same path as its first child.
it doesn't right? because the first child has an empty path : '' , and the main route has a 'product-usages' path
An empty string as a path means "the same path of my parent"
You keep seeing list component?
Yes
add pathMatch: 'full' to the empty path route.
ok, let me see
so you say, leave it like this , right { path: 'product-usages', children: ProductUsageRoutes, data: { minVersion: ProteinRoutingMinApiVersions.PROTEIN_PRODUCT_USAGES_MIN_VER } }
and the child route like this:
{ path: '', component: ProductUsageListPage, pathMatch: 'full' },
yes
That's how pathMatch works in angular router.
By default it's set to 'prefix', that means that it will pick the first route which path matches the target address from the left.
An empty path will match as prefix every children of its parent.
So if you put it on top of the list, and don't change its pathMatch, it will take precedence on everyone of its siblings.
I see