I am really confused by the Angular 7 router. I want to use the get parameter "token" from any place in the URL.
I use the following code to define several routes.
const myRoutes: Routes = [
{ path: 'register/:token', component: RegisterComponent },
// { path: 'register?token=:token', component: RegisterComponent },
// { path: 'register:token', component: RegisterComponent },
{ path: 'register', component: RegisterComponent },
// ...
]
With the first defined path I am able to use "register/mytoken" and "register/?token=mytoken" to get the token.
// Token from register/123
this.token = this.route.snapshot.paramMap.get('token')
// Token from register/?token=123
this.route.queryParams.subscribe(params => {
if (params.token != null)
this.token = params.token;
});
Any time i try to provide my token directly as get-parameter when calling the website in my browser ("register?token=mytoken"), the router will redirect me to "/register" and I can't get the token with my code above. But when i use "register/?token=mytoken" i will be redirected to "register?token=mytoken" and can use the token.
How can i provide a route for accessing the page with "register?token=123" and retrieve the token?