私は次のようにルータのdeactive
メソッドをオーバーライドしようとしています:ルータで非アクティブなメソッドを無効にする方法は?
輸出クラスAnimationRouterOutletがRouterOutlet { publicRoutes拡張:いずれかを。 private parentRouter:Router;
constructor(_elementRef: ElementRef, _loader: DynamicComponentLoader,
_parentRouter: Router, @Attribute('name') nameAttr: string) {
super(_elementRef, _loader, _parentRouter, nameAttr);
this.parentRouter = _parentRouter;
}
deactivate(instruction: ComponentInstruction){
setTimeout(()=>{
console.log("deactivvated state");
return super.deactivate(instruction);
},1000);
}
activate(instruction: ComponentInstruction) {
console.log(instruction);
return super.activate(instruction);
}
}
あなたが見ることができるように、私は、Webページの変更に遅れを作成しようとしています - 私はいくつかのアニメーションを作成できるようにします。
しかし、これを使用して、私は活字体コンパイラエラーがあります。
: error TS2415: Class 'AnimationRouterOutlet' incorrectly extends base class 'RouterOutlet'. Types of property 'deactivate' are incompatible. Type '(instruction: ComponentInstruction) => void' is not assignable to type '(nextInstruction: ComponentInstruction) => Promise'. Type 'void' is not assignable to type 'Promise'.
どのように私はこの問題を解決することができますか?
ありがとうございます!遅延を追加するために元のルータの「非アクティブ化」を上書きする必要がありますか? – uksz
'routerOnDeactivate()'がコンポーネントに追加され、デフォルトで約束を待つのをサポートします。他のより一般的な方法があるかもしれませんが、私はまだ自分自身をルーティングすることに深く関わっていません。 –
ここではrouterCanDeactivate()が良い選択です。ビューをアンロードする前に待機します。 –