angular - 使用角度将隐藏参数传递给外部链接
问题描述
我想从角度路由器导航并将一些隐藏参数传递到外部链接。
假设我有一个在 www.demo.com 上运行的 Angular 应用程序,我想使用 Angular 路由器导航到带有一些隐藏参数的 www.xyz.com。
我尝试使用 router.navigate() 但我猜它只适用于应用程序,不适用于外部链接。
html
<a class="UserActions-editButton edit-button EdgeButton EdgeButton--tertiary" data-scribe-element="profile_edit_button" type="button" (click)="enterUrl($event)">
<span class="button-text">Enter Url</span>
</a>
零件
enterUrl(event:any){
var final_url = 'www.xyz.com'
this.router.navigate([final_url], { queryParams: {token: this.token}});
}
请提出解决方案。谢谢
解决方案
不,您不能将隐藏参数发送到任何外部链接。
但下面是 Angular 应用程序内部导航的用例。
IMO 为您的用例data
属性将帮助您实现您的要求。
const routes: RouterConfig = [
{path : 'heroes', component : HeroDetailComponent, data : {some_data : 'some value'}}
];
所以,你会像这样得到你通过的内容 -
this.route.data.subscribe(data => console.log(data));
PS:但据我所知,您只能使用data
属性发送静态数据。
第三个路由中的data属性是存储与此特定路由关联的任意数据的地方。在每个激活的路由中都可以访问 data 属性。使用它来存储页面标题、面包屑导航文本和其他只读静态数据等项目。您将在本指南后面使用解析保护来检索动态数据。
推荐阅读
- mysql - 如何根据列中的子字符串进行聚合?
- python - FileNotFoundError: No such file or directory (for Dogs and Cats code)
- c - 如何在函数中调用函数
- php - 如何在 DQL 中使用 RETURNING 更新查询
- ios - 如何在 Swift 中删除领域中的对象
- ruby-on-rails - 为什么“唯一性:真实”验证在我的测试(Rails)中不起作用?
- amazon-web-services - 错误:InvalidProfileError - 尽管有配置文件,但无法找到配置文件(默认)
- javascript - Uncaught Invariant Violation:最小化 React 错误
- python - 用 json.dump 引发 JSONDecodeError("Extra data", s, end)
- docker - 将 env var 从 docker run cmd 在 jenkinsfile 中传递给 dockerfie