0

I'm trying to redirect my app when launching and it's not working. I'm just trying to use router.navigate in my ngOnInit() and it returns false.

I tried to insert it in a setTimeout and then it works.

If you have any idea it would be appreciated :)

ngOnInit() {

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

}
trungk18
  • 19,744
  • 8
  • 48
  • 83
Julien Moreau
  • 151
  • 1
  • 4
  • 16

1 Answers1

0

I would try it like this:

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']);
    }
}