Angular 5 - redirect page to homepage on browser refresh
Import Router
import { Router } from '@angular/router';
Initiate Router in Constructor
export class LoginComponent implements OnInit {
constructor(private router:Router) {}
loginCheck() {
/*Your HTTP REQUEST HERE */
this.router.navigate(['/*Your Path Here*/'])
}
}
As mentioned by Chris Sharp, your app is doing exactly what it should do, routing to the place that the url is pointing to, since you have not told it otherwise.
What you can do, is that in your app.component
you can in OnInit
redirect to root. This then means that when app is (re)initialized, you are being redirected to root page.
export class AppComponent {
constructor(private router: Router) {}
ngOnInit() {
this.router.navigate([''])
}
}