Reputation: 7024
I'm trying to read a query string parameter inside the canActivate
method of an Angular guard. Unfortunately, the queryParams
parameter from both ActivatedRouteSnapshot
and RouterStateSnapshot
are empty, even though the query string exists.
Example: bla.com/?uid=123
That query string parameter can be sent to any URL and i want my guard to be able to look at it.
Upvotes: 18
Views: 14996
Reputation: 1654
Or if you are using parameter in your route:
canActivate(route: ActivatedRouteSnapshot) {
console.log("Id:", route.params['uid']);
}
Upvotes: 3
Reputation: 366
Example url: http://example.com/oper/sale?code=you_code_here
import { ActivatedRouteSnapshot } from "@angular/router";
...
canActivate(route: ActivatedRouteSnapshot) {
console.log("code", route.queryParams.code);
}
Upvotes: 35