At the start of application i want to load child route.
Right now URLcome but respective component not load on that section but when again hit the actual URL it comes.
like route configure is
const appRoutes: Routes = [ { path: 'a', component: AComponent, children:[ { path:'x',component:AXcomponent } ] }, { path: 'b', component: bComponent, } ]
Now i want to load path a/x
how i will load at the start of page ?
Default is "/" (the root path). The path-matching strategy, one of 'prefix' or 'full'. Default is 'prefix'. By default, the router checks URL elements from the left to see if the URL matches a given path and stops when there is a config match.
With child routes, you can have a component-like structure defined for the routes in your app. It is critical as there are views that the user should not be able to access unless they are in a particular view. This way, the structure becomes tree-like, just like the structure of components.
First, add links to the two components. Assign the anchor tag that you want to add the route to the routerLink attribute. Set the value of the attribute to the component to show when a user clicks on each link. Next, update your component template to include <router-outlet> .
Add empty path routes as redirect automatically
const appRoutes: Routes = [ { path:'', redirectTo: 'a', pathMatch: 'full' }, { path: 'a', component: AComponent, children:[ { path:'', redirectTo: 'x', pathMatch: 'full' }, { path:'x', component: AXcomponent } ] }, { path: 'b', component: bComponent } ];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With