2016-10-05 9 views
0

私は起動時にリダイレクトしようとしていますが、動作していません。私は単にngOnInit()でrouter.navigateを使用しようとしていて、falseを返します。ngOnInitにリダイレクトする角度2

setTimeoutに挿入しようとしましたが、動作しました。

あなたはそれが理解されるであろう任意のアイデア:)

ngOnInit() { 

    // On redirige au lancement sur la page hors connexion 
    setTimeout(() => this._router.navigate(["/hors-connexion"])); 

} 
+0

は、より多くの情報のためのコードを追加します。 – micronyks

+0

それはミクロンクを行った:) –

+2

[mcve]を与えてください。 – jonrsharpe

答えて

1

を持っている場合、私はこのようにそれをしようとするだろう:

import { Router } from '@angular/router'; 

@Component({ 
    selector: 'test-component', 
    template: '<ng-content></ng-content>' 
}) 

export class TestComponent { 

    constructor(
     public router: Router 
    ) { } 

    ngOnInit() { 

     this.router.navigate(['hors-connexion']); 
    } 
}