Route Guards, Resolvers and Protected Routes
Learn Route Guards, Resolvers and Protected Routes (Phase 6 · Routing (Core), Angular) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.
Functional guards • A guard decides whether navigation may proceed. Modern guards are functions that use inject() and return boolean , a UrlTree (redirect) or an Observable/Promise of those. • Types: canActivate (may enter), canActivateChild , canMatch (may this route be matched/loaded: use for role-based lazy routes), canDeactivate (leave with unsaved changes). • Returning a UrlTree ( router.createUrlTree(['/login']) ) is the idiomatic redirect.