代码之家  ›  专栏  ›  技术社区  ›  AlanObject

角度如何获取坏链接的URL

  •  1
  • AlanObject  · 技术社区  · 6 年前

    在我的应用程序中,我有一个与路由器的通配符匹配的组件来捕获这样的广告链接:

    const route: Routes = [
      { path: '', component: HomeComponent },
      { path: 'signup', component: SignupComponent },
      { path: 'login', component: LoginComponent },
           (etc)
      { path: '**', component: BadlinkComponent }
    ];
    

    坏链接组件 我导入 阿维瓦特德鲁特 对象:

    export class BadlinkComponent implements OnInit {
      constructor(private router: ActivatedRoute) { }
    

    但是我找不到给我错误路由的属性或方法。有人能指出我错过了什么吗?

    2 回复  |  直到 6 年前
        1
  •  0
  •   Rohit.007    6 年前

    snapshot

    export class BadlinkComponent implements OnInit {
     constructor(private router: ActivatedRoute) {
        console.log(router.snapshot['_routerState'].url); 
     }
    }
    
        2
  •  2
  •   Sumama Waheed    6 年前

    url ActivatedRoute

    const url: Observable<string> = route.url.map(segments => segments.join(''));