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

Primitive Types in TypeScript

In TypeScript, primitive types are the most basic data types, and they are the building blocks for handling data. They correspond to simple ...