navigation to other page in a function using next.js

2 years 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