在Angular 4防护中读取查询字符串参数?

vin*_*nux 2 angular

我正在尝试在canActivateAngular Guard 的方法中读取查询字符串参数。不幸的是,queryParams来自ActivatedRouteSnapshot和的参数RouterStateSnapshot是,即使查询字符串存在,也是空的。

示例:bla.com/?uid = 123

该查询字符串参数可以发送到任何URL,我希望我的警卫能够查看它。

小智 5

网址范例:http : //example.com/oper/sale? code= you_code_here

import { ActivatedRouteSnapshot } from "@angular/router";
...

canActivate(route: ActivatedRouteSnapshot) {
    console.log("code", route.queryParams.code);
}
Run Code Online (Sandbox Code Playgroud)