iT邦幫忙

0

angular 抓出router child

import { ActivatedRoute, Params, Router } from '@angular/router';

constructor(private activatedRoute: ActivatedRoute){
}


this.activatedRoute.params.subscribe( (params)=>{
    //子router抓不到
})


{ path: 'a', component:aComponent, children: [
        { path: 'b', component: bComponent},
        { path: 'f', component: bComponent},
        { path: 'g', component: bComponent}]},
{ path: 'c', component:cComponent},
{ path: 'd', component:dComponent},
{ path: 'e', component:eComponent},

假定連線到 /a/b,/b是/a的子網路,如果是/c,/d,/e,activatedRoute都抓得到,但/a/b抓不到,目前想抓出是在哪個子網路b,f,g

本來想用ngAfterViewChecked() {}完再去抓網址,但感覺方法不太恰當

1 個回答

0
joneshong
iT邦新手 5 級 ‧ 2018-10-09 18:10:21

試試這樣

import { Router } from '@angular/router';

constructor(private _router: Router){
    this._router.event.subscribe(console.log)
}


Zaku iT邦新手 4 級 ‧ 2018-10-15 11:23:52 檢舉

大大我試了一下沒有.event這個object

我要發表回答

立即登入回答