All files / projects/organization-management/src/app/guards redirect-first-to-parent.guard.ts

85.71% Statements 6/7
0% Branches 0/1
100% Functions 1/1
85.71% Lines 6/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 1526x 26x         26x 7x   7x     7x    
import { inject } from '@angular/core';
import { ActivatedRouteSnapshot, Router, RouterStateSnapshot, UrlTree } from '@angular/router';
 
/**
 * Redirects the user to the parent page if the requested page is the starting page (first page the user requested)
 */
export function redirectFirstToParentGuard(_: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean | UrlTree {
  const router = inject(Router);
 
  Iif (!router.navigated) {
    return router.parseUrl(state.url.replace(/\/\w+$/, ''));
  }
  return true;
}