The truth is that I'm new to this angular. I have difficulties with the guard since I have not been able to create one to be able to create a login in the web app that I am developing. If someone can provide me with an example that is clear of a login in angular 7. Since days ago I posted my problem but nobody could give me information about this.
I don't know if you have already generated all the necessary files or what structure you want to have in the project. I always have a guard and an authentication service, these are the commands to generate them:
auth.service.ts :
I always create all of the app's authentication methods here, such as login, registration, logout, etc.
auth.guard.ts :
Here the guard checks if it is logged in or not, every time someone tries to enter a route that has the
canActivate: [AuthGuard]
.app-routing.module.ts :
Then in the you call the del
login.component.ts
method .signIn()
auth.service.ts
I hope I've helped. Cheers
I have done similar as indicated by Pacne, it works normally for me, there is only a small fix, I navigate in my rtuas, daughter rytas, etc, all validated with localStorage, and obtaining services from a backend, but if for example I am in a daughter route (route child), and I give it f5, (my guard if it validates that it is authenticated as admin or another role, as I mention when I navigate), but for example I go to the dashboard (which is a route child), and I give it f5, the guard it sends the null roles, I give f5 again and now if it detects me, which I think as soon as it loads the document, it first looks for the guard before accessing the component, that's why it comes out empty, although it shouldn't, since in the auth.isLoggedIn (analogous to mine), I ask for localStorage, but it gives me null, as I said it is solved with an f5, but that should not happen, I don't know if you have an idea or something more specific to look for.thanks greetings