Answer the question
In order to leave comments, you need to log in
How to correctly redirect the user to the authorization window?
When the application starts, the user always enters the root route.
This route is HARD-coded in the application module.
How to make an unauthorized user immediately routed to the authorization window component right at the start of the application? So that the main interface does not even try to be displayed?
Where should this logic be located - in app.module.ts?
(Yeah, I'm a complete noob in Angular :)
Answer the question
In order to leave comments, you need to log in
The correct solution is to make Guard and slip it into all protected routes with the canActivate parameter:
The Guard itself has a canActivate() method that decides whether it is now possible to enter this route. If not, then the method should return false - but before that, pull this.router.navigate(['/loginPage']);
Those. the redirect happens inside the guard.
More about guards for example here: metanit.com/web/angular2/7.7.php
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question