Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You can use the router.push method provided by Next.js to navigate to the same page when the user clicks on Continue. Here is an example:

import { useRouter } from "next/router";

function MyForm() {
  const router = useRouter();

  function handleSubmit(event) {
    event.preventDefault();
    // Process the form data here...

    // Navigate to the same page
    router.push(router.pathname);
  }

  return (
    <form onSubmit={handleSubmit}>
      {/* Form fields here */}
      <button type="submit">Continue</button>
    </form>
  );
}

In this example, we are importing the useRouter hook from Next.js and initializing it in the component. When the user submits the form, we prevent the default behavior (page reload) and process the form data. Then we call router.push with the current pathname to navigate to the same page without reloading it.