1

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 ?

Rui Sebastião
  • 855
  • 1
  • 18
  • 36
  • the same way you're using to navigate to any URL: using a link with routerLink, or using router.navigate[ByUrl](). – JB Nizet Apr 11 '18 at 20:59
  • Possible duplicate of [How to get param from url in angular 4?](https://stackoverflow.com/questions/45997369/how-to-get-param-from-url-in-angular-4) – Dmitry Grinko Apr 11 '18 at 21:30
  • what do you mean by "hange the unit parameter "? Can't really understand the question. – ForestG Apr 12 '18 at 07:38
  • is it link somewhere e.g. you are having `button`s? or it's based on condition in component? You can add some more code regarding same. – Anshuman Jaiswal Apr 12 '18 at 07:48
  • i think that seeing the routes configuration its pretty clear to see what means to change the serialnumber... i have a list of units with a specific serial number and i navigate through them changing the ':serialnumber' route parameter. my question was if it is possible to change only that parameter and keep the current childs route (../consumptions/daily for example) – Rui Sebastião Apr 12 '18 at 07:50

0 Answers0