【发布时间】:2021-10-05 02:03:57
【问题描述】:
我能够使用路由paramMap 获得authkey 值,但我们如何获得网址。例如,我想检查 URL 是否包含 resetpassword 文本,如下面的链接所示。我们如何在 Angular 中做到这一点?
我们如何获取 URL 或者 URL 是否在页面加载时包含某些文本?检查 URL 是否包含“resetpassword”文本。
代码
ngOnInit(): void {
this.router.paramMap.subscribe((paramMap) => {
console.log("paramMap" , paramMap)
this.code = paramMap.get('authkey');
if (this.code) {
this.code = paramMap.get('authkey').replace('authkey:', '');
this.getEmail(this.code);
}
});
}
示例网址
http://localhost:4200/#/login/resetpassword/authkey:6762b362-1a62-4077-8ae4-78b381REX7JEXE4a8f30
【问题讨论】:
-
这能回答你的问题吗? Get current url in Angular
-
不,因为我还想检查 url 是否包含特定字符串
-
真的找不到解决办法
-
好的。 2 种方法:您可以按照其他答案中的说明获取 url,然后在 google 中搜索“js 检查字符串是否包含子字符串”-> stackoverflow.com/questions/1789945/…。或者你直接谷歌“js检查url是否包含文本”->stackoverflow.com/questions/4597050/…
-
let subscring ="resetpassword" console.log("thisss" ,this.router.url.includes(subscring))
标签: angular typescript