nextjs route

nextjs

In a Next.js app, a route is a URL pattern that is associated with a specific component. When a user navigates to a route, Next.js will render the associated component.

You can define routes in Next.js using the Link and Router components from the next/link and next/router packages, respectively.

Here’s an example of how you can define a route in Next.js:

import Link from 'next/link'

function Home() {
    return (
        <div>
            <Link href="/about">
                <a>About</a>
            </Link>
        </div>
    )
}

function About() {
    return (
        <div>
            This is the about page.
        </div>
    )
}

export default function App() {
    return (
        <Router>
            <Home path="/"/>
            <About path="/about"/>
        </Router>
    )
}

In this example, we have two components: Home and About. The Home component contains a Link component that points to the /about route, and the About component is associated with the /about route.

When a user clicks the link in the Home component, they will be redirected to the /about route and the About component will be rendered.