2016-03-26 5 views
1

私は次のようにルータの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'.

どのように私はこの問題を解決することができますか?

答えて

2

このようにオーバーライドされた関数の戻り値の型を変更することはできません。戻り値の型は、スーパークラスの戻り値の型と同じ型である必要があります。

CanDeactivateを実装すると、ルーターがコンポーネントからルーティングする前に待つことができます。

+0

ありがとうございます!遅延を追加するために元のルータの「非アクティブ化」を上書きする必要がありますか? – uksz

+0

'routerOnDeactivate()'がコンポーネントに追加され、デフォルトで約束を待つのをサポートします。他のより一般的な方法があるかもしれませんが、私はまだ自分自身をルーティングすることに深く関わっていません。 –

+2

ここではrouterCanDeactivate()が良い選択です。ビューをアンロードする前に待機します。 –

関連する問題