问题
I have the following route configuration:
const routes: Routes = [
{
path: '',
component: HomeComponent,
canActivate: [AuthGuard],
children: [
{
component: DashboardComponent,
path: ''
},
{
component: UnitComponent,
path: 'unit/:serialnumber',
children: [
{ path: '', redirectTo: 'realtime', pathMatch: 'full'},
{
path: 'manager',
component: UnitManagerComponent,
canActivate: [SysAdminGuard]
},
{ path: 'realtime', component: UnitRealtimeComponent },
{ path: 'history', component: UnitHistoryComponent },
{ path: 'consumption', component: UnitConsumptionComponent },
{ path: 'consumption/:range', component: UnitConsumptionComponent },
{ path: 'edit', component: UnitEditComponent }
]
}
]
}
...
image that i am in current route state
http://127.0.0.1:4200/#/unit/000000003/consumption/monthly
and i want to navigate to another unit with a different serialnumber:
http://127.0.0.1:4200/#/unit/000000001/consumption/monthly
if i make
this.router.navigate(['/unit','000000001'])
i will go to http://127.0.0.1:4200/#/unit/000000001/realtime
is there any way to change a specific parameter in the route and keep the childs route ?
来源:https://stackoverflow.com/questions/49784350/angular-routing-keep-child-parameters