#Angular SSR: Guard returns false on queryParams check

3 messages · Page 1 of 1 (latest)

edgy basin
#

You should not perform navigation inside the guard, instead return UrlTree or RedirectCommand to tell the router to do a different navigation instead

brave apex
#

The Guard:


export const redirectGuard: CanActivateFn = (route, _): boolean | UrlTree => {
  const redirect = route.queryParams['redirect'];
  const router = inject(Router);

  if(!redirect) {
    return router.createUrlTree(['/error']);
  }

  return true;
};