The app under development is hosted within an iframe.
I have the following routes configured in my app:
const routes: Routes = [
{
path: '',
pathMatch: 'full',
redirectTo: 'list'
},
{
path: 'list',
component: ListComponent,
canActivate: [CanActivateRoute]
},
{
path: 'dashboard',
loadChildren: './modules/dashboard/dashboard.module#DashboardModule'
}
];
@NgModule({
imports: [RouterModule.forRoot(routes, { enableTracing: true })],
exports: [RouterModule],
providers: []
})
export class AppRoutingModule { }
In the ListComponent
, OnInit
method, I have used the following code to get query string params:
this.router.events.subscribe(val => {
if (val instanceof RoutesRecognized) {
console.log("val.state.root.firstChild.params: " + val.state.root.firstChild.params);
}
});
const firstParam: string = this.route.snapshot.queryParamMap.get('id');
None of these seem to work. The url I have for my application is as follows:
https://company.com/#/app-dev/list?id=3
QueryParamMap
or RoutesRecongnized
doesn't seem to get the query string "id=3" in the url. It always returns null.
Can anyone help me how to retrieve the query params / query string from url in angular app?