I'm trying to restrict routes to be available only to authenticated users. So far I've added a service call in every route component constructor to check if the user is logged. If not, you get redirected to the login route(index):
logCheck(){
this.af.auth.subscribe(user => {
if(!user){
this.router.navigate(['']);
}
});
It works. But I'm not sure if using the constructor of each route component for this is the correct way of doing things, because you are actually loading the component before being kicked out. Is there a better way to do it? Like using additional params in the app.routes const maybe?