Check out my article for this code. Prevent Route Changes and Unsaved Data Loss in Next.js
This is a Next.js project bootstrapped with create-next-app.
First, run the development server:
npm run dev
# or
yarn dev
# or
pnpm devOpen http://localhost:3000 with your browser to see the result.