2017-08-30 61 views
0

我建立了我的路由如下:angular2-nativescript嵌套的組件頁面事件

const pages = [ 
    { 
     path: "", 
     component: BaseComponent, 
     children: [ 
      { path: "scan", component: ScanComponent } 
     ] 
    } 
]; 

因此,舉例來說,如果你去/掃描,它涉及BaseComponent和ScanComponent。

的BaseComponent包含<router-outlet></router-outlet>這使得ScanComponent的內容。

這一切工作正常,但:

在ScanComponent我有以下幾點:

constructor(private page: Page) { 
    this.page.on('navigatedTo',() => console.log('navigatedTo')); 
} 

並且該事件不會被調用。

如果我刪除從父路由線路component: BaseComponent,該事件被稱爲,但當然休息的其他事情。

我怎樣才能確保此事件總是被調用,不管是否有一個父組件或不?

這是一個NativeScript應用中的根組件包含<page-router-outlet></page-router-outlet>

回答

0

好吧,我想通了......因爲「頁」是一個nativescript概念,其事件僅路由是否裝入page-router-outlet應用,也是NativeScript的概念。它只有意義。

了幾個小時谷歌搜索後,爲什麼我總是找出答案張貼到StackOverflow上之後!? *嘆*我猜這是某種橡皮鴨編程。