What this thread does
Do first: attach a CanActivateFn to canActivate and enforce the same resource permission independently at the API boundary before exposing protected data.
Short answer
As of 2026-11-19, Angular 22.3.0 is the reference baseline. Return a redirect result when denying navigation, rerun guards for authorization-relevant query changes, and include direct API requests in acceptance coverage.
Choose / don't choose
- canActivate: choose to check permission to activate the requested route; don't infer API security from a hidden page (guard API).
- canActivateChild: choose a consistent policy for children of a protected section; don't assume a previously activated parent's guard reruns for every child navigation (guard guide).
- canMatch: choose to select among route variants; don't interpret false as an unconditional forbidden result. Angular tries another matching route (CanMatchFn).
Not for: Next.js/Supabase admin panels; see case-admin-panel-roles-nextjs-supabase-who-can-see-what.
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
Route.canActivate | Return true only when the required permission is present, otherwise a redirect/false | Current Angular Router | CanActivateFn |
| Guard/resolver policy | 'paramsOrQueryParamsChange' when matrix or query parameters affect permission; default 'paramsChange' excludes query params | Current Angular Router | policy API |
| Alternative guard/resolver policy | 'pathParamsOrQueryParamsChange' when path/query changes matter but matrix parameters do not; a predicate receives the from/to route snapshots | Current Angular Router | policy API |
Route.canMatch | false skips this route; return a UrlTree/RedirectCommand to redirect | Current Angular Router | CanMatchFn |
RedirectCommand | const loginPath = router.parseUrl("/login"); return new RedirectCommand(loginPath, { skipLocationChange: true }); is the documented redirect form; choose navigation options deliberately | Current Angular Router | RedirectCommand |
onSameUrlNavigation | Default 'ignore'; use 'reload' only if same-URL processing is required, alongside the separate guard rerun policy | Current Angular Router | route behavior |
The application's route data may name a required permission, but the name is application-defined. Read permission inputs from the target route snapshot. For an asynchronous guard return its Promise/Observable; the router uses the first emitted result and unsubscribes (return contracts).
Order of operations
1. Resolve the current signed-in identity and relevant permission before returning a guard result; a loading/unknown state is not approval. If denied, return router.parseUrl('/login') or a RedirectCommand within the guard evaluation rather than returning false and separately calling navigate. 2. Configure reruns for query-based tenant/resource selectors. Changing the same URL's authentication state is separate: the router may ignore the navigation unless same-URL processing is enabled, and runGuardsAndResolvers: 'always' may be needed for the intended rerun. 3. Validate permissions on every request. Deny by default, check ownership or policy even for guessed IDs, and do not trust a route guard, hidden button or client-provided role (OWASP authorization). 4. Cover allowed, anonymous, denied and revoked-permission navigation; change only the authorization-relevant query field and confirm the protected component does not activate on denial. Include alternate routes sharing the same path. 5. Repeat the operations as direct API calls without loading Angular. Assert rejection before any protected data or write side effect for missing identity, wrong role, other-user resource and other tenant. Assert permitted actions still succeed. These are application acceptance conditions.
Known failures and fixes
| Error (short quote) | Cause | Fix | Source |
|---|---|---|---|
Cannot match any routes. URL Segment: | A NoMatch is passed to noMatchError | Return an explicit redirect for denial, or provide an intentional safe fallback; don't bypass permission just to make a route match | recognizer source, matching contract |
paramsChange | Default rerun policy leaves query-only permission changes unchecked by the existing guard | Select paramsOrQueryParamsChange or a narrow predicate; still enforce server authorization | policy API |
The second row names a policy symptom, not an exception string. Issue #31843 requested manually triggering all resolvers on route change and was closed as completed on 2026-09-04; use the documented current policies rather than copying historical nonce-query tricks.
Missing
- The linked source does not confirm: the illustrative permissionGuard identifier.
- The API framework, permission model and revocation latency are unspecified. No client configuration alone proves server enforcement; define expected unauthorized status and absence of side effects in that API's contract.
Started from a post by @Angular team, packaged by the editor. Original post