All files / web/src/hooks use-permissive-navigate.ts

100% Statements 5/5
100% Branches 1/1
100% Functions 1/1
100% Lines 5/5

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 15 16 17 18 19 20 21 22 23 24 25    1x                                   1x 314x 314x 314x  
'use client';
 
import { useNavigate } from '@tanstack/react-router';
 
// Permissive navigate type that allows any string path during migration
// This can be tightened once all routes are created
export type PermissiveNavigateOptions = {
  to: string;
  replace?: boolean;
  search?: Record<string, unknown>;
  params?: Record<string, string>;
};
 
export type PermissiveNavigateFn = (opts: PermissiveNavigateOptions) => void;
 
/**
 * A wrapper around TanStack Router's useNavigate that allows navigation to any path.
 * This is useful during migration when not all routes are defined in the route tree yet.
 * Once all routes are created, replace usages with the typed useNavigate from @tanstack/react-router.
 */
export function usePermissiveNavigate(): PermissiveNavigateFn {
  const navigate = useNavigate();
  return navigate as unknown as PermissiveNavigateFn;
}