Auto redirecting after n seconds using Angular 2
its a-bit sketchy but this will work.
setTimeout(() => {
setTimeout(() => {
this.router.navigateByUrl("/home");
});
}, 3400);
}
You can inject and use Router
from @angular/router
and navigate in setTimeout
.
import { Router } from '@angular/router';
constructor(private router: Router) {}
ngOnInit() {
// do init at here for current route.
setTimeout(() => {
this.router.navigate(['nextRoute']);
}, 5000); //5s
}