All files / app/components Redirect.tsx

100% Statements 10/10
100% Branches 1/1
100% Functions 2/2
100% Lines 10/10

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 159x 9x   9x 10x 10x 8x 4x 4x   4x   10x    
import { useRouter } from "next/router";
import { useEffect } from "react";
 
export default function Redirect({ to }: { to: string }) {
  const router = useRouter();
  useEffect(() => {
    if (router.asPath === to) {
      console.warn("Prevented redirect to same page");
      return;
    }
    router.push(to);
  }, [router, to]);
  return null;
}