freshbm
freshbm

Reputation: 5622

How to define and call child route

I have problems creating child routes in main routing module.

{ path: 'vehicles/vehicles', component: VehiclesComponent, data: { permission: 'Pages.Vehicles' }, children: [{ path: 'statistic', component: StatisticVehicleComponent }] },

and I'm trying to redirect to it from code:

this.router.navigate(['/app/main/vehicles/vehicles/statistic']).then(() => {
            window.location.reload();
        });

but I'm always getting error that route doesn't exist.

What I'm doing wrong, should I register somewhere else the route or I'm calling this router in wrong way?

Upvotes: 1

Views: 343

Answers (1)

Nikhil
Nikhil

Reputation: 6643

You can define your routes like this. Move your parent component to empty path of child route.

{ path: 'vehicles/vehicles', 
    children: [
      { path: '', component: VehiclesComponent, data: { permission: 'Pages.Vehicles' } }
      { path: 'statistic', component: StatisticVehicleComponent }
    ]
}

Refer Angular Documentation for more info.

Upvotes: 1

Related Questions