Reputation: 2057
I have parent route called "Profile" and inside I have child routes like basic, company, contacts. So when I click on the parent route like Profile then by default it should show the content present in the basic component.
export const appRoutes: Routes = [
{ path: 'profile', component: ProfileComponent,
children: [
{
path: 'basic',
component: BasicComponent,
pathMatch: 'full'
},
{
path: 'company',
component: CompnayComponent
},
{
path: 'contacts',
component: ContactsComponent
},
{
path: 'compliance',
component: ComplianceComponent
}
]
}
So when the user clicks on Profile then automatically the content in the basic should display. So how to achieve this? Can anyone help me?
Upvotes: 3
Views: 402
Reputation: 21397
add redirect to basic in your routes config:
export const appRoutes: Routes = [
{ path: 'profile', component: ProfileComponent,
children: [
{
path:'',
redirectTo: 'basic',
pathMatch: 'full'
},
{
path: 'basic',
component: BasicComponent,
pathMatch: 'full'
},
{
path: 'company',
component: CompnayComponent
},
{
path: 'contacts',
component: ContactsComponent
},
{
path: 'compliance',
component: ComplianceComponent
}
]
}
Upvotes: 1
Reputation: 2244
Add a redirect to basic in the child routes
{path: '', redirectTo: 'basic'}
If you now navigate to /profile/
it will redirect to /profile/basic
Upvotes: 0