1

I'm learning nextjs but got an error,

import { useRouter } from "next/router";
export default function Auth() {
  const router = useRouter();
  const root = router.query.auth;

  if (root !== "signin" && root !== "signup") {
    router.replace("/404");
  }

  return <div>form</div>;
}

result

can someone explain to me why I got an error?

ubi goreng
  • 53
  • 7
  • Does this answer your question: [use NextRouter outside of React component](https://stackoverflow.com/a/66268808/1870780)? Essentially, you'll need to call `router.replace` inside a `useEffect`. – juliomalves May 23 '21 at 14:19

1 Answers1

0

You didn't Import router, In next if you wanna handle routing best is do on serverside it will solve your issue.

Amit Shakya
  • 962
  • 3
  • 16
  • 30