In my angular 12 project, I have applied canActivate on routes but due to which routes are not working on browser page reload.
In canActivate , i am checking data is present or not in localStorage for currentUser. but when I reload page I didn't get value for localStorage item.
If I remove canActivate then page reload works fine.
Is there any other way in which I can prevent user for accessing routes if not logged in?
You can try to check for logged in in NgOnInit() and redirect user to other route
As I know that for each route goes with a component and a component got NgOnInit() of the life cycle