简体   繁体   English

HashLocationStrategy和位置策略导入后未检测到路径Angular 2和Typescript

[英]Path not detected after HashLocationStrategy and Location Strategy Import.Angular 2 & Typescript

if (location.pathname.includes('aboutUs')) {
      this.isShow = false;
     }
  1. Its Working fine until HashLocationStrategy and Location Strategy Import wasn't done. 在未完成HashLocationStrategy和位置策略导入之前,它可以正常工作。
  2. After Import because of # in url it was unable to search the given path. 导入后,由于网址中有 ,因此无法搜索给定的路径。

You can use this approach to work with ActivatedRoute , paths, and get url params and query params. 您可以使用此方法来使用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...');
        }
      }
    });
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM