Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

keeping default route with parent route in angular

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?

like image 544
youi Avatar asked Mar 19 '26 08:03

youi


1 Answers

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
        }
    ]
}
like image 81
Fateh Mohamed Avatar answered Mar 20 '26 21:03

Fateh Mohamed



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!