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 | 8x 8x 4x 6x 6x 6x 3x 3x 3x 6x | 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; } |