What is Link component in Next.js ?
Last Updated :
17 Jul, 2024
In Next.js, Link is used to create links between pages in a Next.js app. To create a link, insert the <Link> component into your page, and specify the path to the page you want to link to.
Link Component
The Link component in Next.js is a built-in feature that provides client-side navigation between pages without a full page refresh. It optimizes performance by pre-fetching linked pages, enhancing user experience in single-page applications.
Syntax:
import Link from 'next/link';
<Link href="/https/www.geeksforgeeks.org/target">
Go to Target
</Link>
The <Link> component also has the following properties:
- href: The path to the page you want to link to.
- rel: The type of link. Possible values are "external", "internal", or "none".
- title: The title of the link.
- active: Whether the link is active or not.
Steps to Create Next.js App
Step 1: To create a new NextJs App run the below command in your terminal:
npx create-next-app GFG
Step 2: After creating your project folder (i.e. GFG ), move to it by using the following command:
cd GFG
Project Structure:
It will look like this.

Example: Adding Link in Next.js. To use the link component first we are going to create one new file name 'first.js' with the below content.
JavaScript
// Filename - pages/first.js
// Importing the Link component
import Link from 'next/link'
export default function first() {
return (
<div>
This is the first page.
<br/>
{/* Adding the Link Component */}
<Link href="/">
<a><button>Go to Homepage</button></a>
</Link>
</div>
)
}
JavaScript
// Filename - pages/index.js
// Importing the Link component
import Link from 'next/link'
export default function Homepage() {
return (
<div>
This is the Homepage page - GeeksforGeeks
<br/>
{/* Adding the Link Component */}
<Link href="/first">
<a><button>Go to first page</button></a>
</Link>
</div>
)
}
Here we are first importing our Link component from 'next/link'. Then we are using this component to navigate between pages.
Step to Run Application: Run the application using the following command from the root directory of the project.
npm run dev
Output: This will start the development server for your Next.Js application.
Similar Reads
Next.js Link Component The Link component in Next.js is used to navigate between pages in a Next.js application. It enables client-side navigation, which provides a smoother user experience by avoiding full-page reloads. This component is crucial for building Single Page Applications with Next.js, as it allows for efficie
2 min read
Next.js Components Next.js components are integral to building modular and efficient applications, offering tools like Image, Link, Script, and Font to handle media, navigation, scripts, and typography effectively. These components enhance performance and streamline development in Next.js.Table of ContentWhat is a Com
4 min read
Link Component in React Router React Router is a powerful library in ReactJS that is used to create SPA (single-page applications) seamlessly. One of the components of the React Router is Link. In this article, we will be seeing the working of the Link component, various props, and usage of the Link component within React Router
5 min read
Next.js Components : <Script> The <Script> component in Next.js allows you to load third-party scripts efficiently, optimizing performance and enhancing control over when and how scripts are executed within your application.In this post, we will learn about the Next.js Script component.Table of ContentScript ComponentsSynt
6 min read
Server Components in Next.js Server Components in Next.js offer a way to build components that are rendered on the server rather than on the client. This feature enhances performance by reducing the amount of JavaScript sent to the browser and allows for faster initial page loads. In this post, we will explore the Server Compon
4 min read