AuthGuard in angular 7 with example | Angular 7 Tutorials

For Consultation : +91 9887575540

Stay Connected :

Auth Guard in Angular 7 Login Example

In this example, I have taken a simple login example where a user may open dashboard after login only after successful login username will be stored into localstorage which is authentication for auth guard.

Take the Following steps :

  1. create two components login and dashboard.(ng g c /login/login, ng g c /dashboard/dashboard)
  2. Create a service “MyService” (ng g s MyService)
  3. Create a authguard(ng g g authguard)

Add Following code into service

Add Following code into authguard

Add Following code into login


Write Following code into app.module.ts


Select your currency
Open chat
Powered by