angular - HashLocationStrategy 和 Location Strategy Import.Angular 2 & Typescript 后未检测到路径
问题描述
if (location.pathname.includes('aboutUs')) {
this.isShow = false;
}
- 在 HashLocationStrategy 和 Location Strategy Import 未完成之前,它的工作正常。
- 导入后由于# in url 无法搜索给定的路径。
解决方案
您可以使用这种方法来处理ActivatedRoute
、 路径,并获取 url 参数和查询参数。
export class YourComponent {
constructor(private activatedRoute: ActivatedRoute) { }
this.activatedRoute.url.subscribe(urlSegments => {
for (const item of urlSegments) {
if (item.path === 'aboutUs') {
console.log('Awesome! Path Found...');
}
}
});
}
推荐阅读
- android - 如何使用“git cherry-pick”手动更新自定义 rom 的安全补丁?
- python - 如何使用 plotly express 创建子图?
- yugabyte-db - 接口连接限制配置
- reactjs - 参数对象(API 密钥)未与 axios.create 一起发送
- python - 解析 json 文件时获取 0 条记录,如果关键属性不存在
- python-3.x - pyinstaller 命令创建 exe 但不能正常工作
- amazon-web-services - 直接从 Lambda 调用 Kinesis Firehose 与 Kinesis Stream
- amazon-redshift - 无法让 AWS Data Pipeline 连接到 Redshift
- tensorflow - 如何修复使用 tensorflow 实现贝叶斯神经网络时的 fetch 参数错误
- url - 如何从 blob url 或 m3u8 下载 mp4 视频?