0

i am protecting all my routes with a single Authguard and right now i am using in each route

canActivate: [AuthguardService]

my application has 30+ routes and so i need to type this 30 times in each route. Is there a way to protect all my routes with only one entry of my authguard ?

Thanks

GreekSwiss
  • 37
  • 8
  • If your routes are all children of the same base route, you can modify your guard and use CanActivateChild instead of CanActivate. Otherwise, you're stuck, although I'd advise copy/pasting rather than typing, and 30 times isn't all that bad ;-) – Will Alexander Feb 17 '22 at 12:04
  • well thats the case, they are not all children of the base route. But thank you for your information. copy/paste works fine ;) – GreekSwiss Feb 17 '22 at 12:29

1 Answers1

0

You could define all the routes as child of one protected route: https://codecraft.tv/courses/angular/routing/router-guards/

Are all the routes on the same module?

jcobo1
  • 1,065
  • 1
  • 18
  • 34