13
非ビューモデルクラス内の現在のルートを取得するには、ルータを挿入してthis.router.history.fragmentを使用することをお勧めしますか?それとも、これはノーですか?Aureliaで現在のルートを取得する
非ビューモデルクラス内の現在のルートを取得するには、ルータを挿入してthis.router.history.fragmentを使用することをお勧めしますか?それとも、これはノーですか?Aureliaで現在のルートを取得する
ルータを注入して現在の命令を取得することができます。このように:
import { inject } from 'aurelia-dependency-injection'; //or framework
import { Router } from 'aurelia-router';
@inject(Router)
export class MyClass {
constructor(router) {
this.router = router;
}
getRoute() {
return this.router.currentInstruction.config.name; //name of the route
//return this.router.currentInstruction.config.moduleId; //moduleId of the route
}
}
(も[コンポーネントを参照してくださいあなたが結合のためにそれを使用したいので、もし、あなたが 'created'方法でそれを得ることができ、' currentInstruction'はまだコンストラクタで 'null'なのであることに注意してくださいライフサイクル](http://aurelia.io/hub.html#/doc/article/aurelia/framework/latest/creating-components/3) –
私は以前のルートのデータを得ています。 – IngoB
おそらくビューがまだ変更されていない可能性があるので、あなたは 'canDeactivate'関数を持っているか確認してください。 –