【发布时间】:2018-04-19 15:04:01
【问题描述】:
我在 Angular 应用程序中使用 OAuth 隐式流身份验证方法。要检索访问令牌,我需要从以下字符串解析参数:
http://localhost/authentication#access_token={0}&expires_in={1}&user_id={2}
经过一番调查,我没有找到任何从此类 URL 检索参数的机制(我发现的所有机制都是基于使用手动字符串拆分。这是否意味着 Angular 没有“开箱即用”的机制来解析URL 片段中的参数,最好的方法是使用 substring() 或 split() 方法?
【问题讨论】:
-
构造函数(私有路由:ActivatedRoute,私有路由器:Router){ this.route .queryParams .subscribe(params => { console.log(params ); }); } 你能在你的根组件中试试这个吗
-
@user183101 你解决过这个问题吗?
-
如果你想在queryParams中使用fragment,应该是这样的:localhost/authentication?access_token={0}&expires_in={1}&user_id={2}#fragment_1