I use the following approach to pass parameters through different routes and I am trying to keep these parameter values on page refresh or opening another tab on the routed page. However, after retrieving these parameters, they lost their values. So, is it possible to keep their values without using :id
etc suffix on the routes? In this scenario, I open the SecondComponent first and then open its Child called SecondChildComponent using tabs.
first.component.ts
details(name) {
this.router.navigate(['/second'], { state: { name: name} });
}
second.component.ts
constructor(private router: Router) {
this.name= this.router.getCurrentNavigation().extras.state.name;
}
routing.module
const routes: Routes = [
{
path: 'second',
component: SecondComponent,
children: [
{
path: '',
redirectTo: 'second-child',
},
{
path: 'second-child',
component: SecondChildComponent
}
]
}
];