Create link in Nextjs

Creating link in nextjs is a bit different when compared to other languages.

Let’s see how it is implemented.

Example code

// pages/index.js (or any other page or component)

import React from ‘react’;

import Link from ‘next/link’;

const HomePage = () => {

 return (

  <div>

   <h1>Welcome to my Next.js App</h1>

   <p>Go to the <Link href=”/about”><a>About Page</a></Link>.</p>

  </div>

 );

};

export default HomePage;

To create a link, you can use the Link component.

In the example above, the Link component is used to wrap an anchor (<a>) tag. The href prop of the Link component specifies the target page.

Leave a comment

Your email address will not be published. Required fields are marked *