angular - 带有GET参数的Angular 7路由器路径
问题描述
我一直在寻找几个小时,但找不到我的问题的有效解决方案......
我的 Angular 应用程序将用户重定向到通过 GET 参数返回 jwt 的 oAuth2 API。我发现了如何使用 Angular 读取 GET 参数,但我的问题是另一回事:
{path: 'authenticate', component: AuthenticationComponent}
这是我为我的 AuthenticationComponent 设置的路由。它按预期工作,没有任何附加参数,但使用单个 get 参数('/authenticate?jwt=123' 而不是 '/authenticate')它不再工作,我的 '**' 路由被激活。
一种解决方法是另一个站点(不是用 angular 编写的),它将用户重定向到 angular 页面并将 GET 参数转换为 URL 参数 ('/authenticate?jwt=123' => '/authenticate/123') 并更改我的路由路径到 'authenticate/:jwt' 但我想用我的角度应用程序来做。
请帮我
解决方案
像这样设置路由器
{path: 'authenticate/:jwt', component: AuthenticationComponent}
并获取组件中的 jwt 值
// top component
import { Router, ActivatedRoute } from '@angular/router';
// constructor arg
constructor(private route: ActivatedRoute) {}
// user method or ngOnInit inside
this.route.params['value'].jwt
模块中的下一个导入路由模块
// top module
import { RouterModule } from '@angular/router';
// import object
imports: [RouterModule.forRoot([])]
这是工作
推荐阅读
- python - 使用 Python 的 Telnetlib 记录 NMEA 句子并将输出重定向到文本文件
- java - java SSLHandshakeException 虽然证书受信任的系统范围
- 3d - Zbrusch Core - 无法雕刻到圆柱体上
- html - 这个定制的引导代码是否需要我缺少的东西?
- javascript - 多动作 API 最佳实践/设计模式
- laravel - 模型的关系并向用户显示余额
- javascript - 如何将流媒体服务价格数组转换为按服务长度分类的对象数组?
- php - 如果用户有名字,如何显示某些内容,如果没有,如何显示其他内容
- javascript - 不使用 getElementById 的多个元素 onclick 的 JS 函数
- javascript - 生成 PDF 并且 PDF 存储在生成它的位置