2015-11-13 5 views
7

私はAureliaフレームワークを使用しています。 navigationInstructionアプリファイル(app.ts/app.js)の情報をユーザーが新しいルート/ページに移動するたびに取得したいのですが、Aureliaの現在のルートを特定します

私はアプリのライフサイクルイベント(アクティブ化とバインド)でこの情報を取得しようとしましたが、情報はありません。

誰でも私にこの問題の解決を手伝ってもらえますか?

ありがとうございます。

答えて

9

は、ルータのナビゲーション「成功」イベントをサブスクライブ:

import {EventAggregator} from 'aurelia-event-aggregator'; 
import {inject} from 'aurelia-dependency-injection'; 

@inject(EventAggregator) 
export class App { 
    constructor(eventAggregator) { 
    this.eventAggregator = eventAggregator; 
    } 

    navigationSuccess(event) { 
    let instruction = event.instruction;  
    // todo: do something with instruction... 
    } 

    attached() { 
    this.subscription = this.eventAggregator.subscribe(
     'router:navigation:success', 
     this.navigationSuccess.bind(this)); 
    } 

    detached() { 
    this.subscription.dispose(); 
    } 
} 

ここES7機能結合およびES6の非構造を使用して、わずかに異なるバージョンです:

import {EventAggregator} from 'aurelia-event-aggregator'; 
import {inject} from 'aurelia-dependency-injection'; 

@inject(EventAggregator) 
export class App { 
    constructor(eventAggregator) { 
    this.eventAggregator = eventAggregator; 
    } 

    navigationSuccess({ instruction }) { 
    // todo: do something with instruction... 
    } 

    attached() { 
    this.subscription = this.eventAggregator.subscribe(
     'router:navigation:success', 
     ::this.navigationSuccess); 
    } 

    detached() { 
    this.subscription.dispose(); 
    } 
} 
+0

手動ナビゲーションを構築する我々にとって良いものは - ありがとうございました – mujimu

関連する問題