navigation to other page in a function using next.js

6 months ago23k times


import { useRouter } from 'next/router'
function App() {
  const router = useRouter()
  const clickEvent= (event) => {
    event.preventDefault()
    router.push('/path-url')
  }


  return (
    <button type="button" onClick={clickEvent}>
      Click Me
    </button>
  )
}


Add Answer

Add a codeAdd Code
Remove adsremove

Latest codes

view all

Latest Snippets

view all