I have setup Single Sign On (SSO) for my app, but I also need to be able to read values from URL parameters (localhost:4200/?id=test&name=testing&email=testing@test.com
) and pass them to an API in the App Component.
A flag (url_enabled
) will determine whether to read from the URL or use the SSO function.
In the App Component, I have tried to get the URL parameters using queryParams
, params
, url
, queryParamsMap
, but none of these seem to be working - I only get empty values.
The code in my App Component is as follows:
app.component.ts
getParamsFromUrl() {
this._router.events.subscribe((e) => {
if (e instanceof NavigationEnd) {
console.log(e.url)
}
})
}
this.route.queryParams.subscribe(params => {
console.log(params);
})
app.component.html
<router-outlet></router-outlet>
app-routing.module.ts
const routes: Routes = [
{path:'*/:id', component: AppComponent},
];
I have tried the solutions I have found from Stack Overflow and other blogs, but haven’t been able to figure out what I am missing. Can someone please suggest a solution?