useRouter in Next js

  • This hook is use to route between pages. Example:


    "use client"
    import React from 'react'
    import { useRouter } from 'next/navigation';

    const Home = () => {
      const router = useRouter()
      return (
        <div>
          <button
            onClick={() => router.push("/contact")}
          >
            Click
          </button>
        </div>
      )
    }

    export default Home



No comments:

Post a Comment

What is Machine Learning?

Imagine you have a friend who is really good at recognizing cats in pictures. You show them lots of cat pictures, and over time, they get be...