![]() |
VOOZH | about |
In Next.js, the Link component is used to create navigation between pages in a Next.js application. Instead of causing a full-page reload (like <a> tag), the <Link> component enables client-side navigation, making transitions faster and smoother. This feature improves performance and creates a better Single Page Application (SPA) experience by pre-fetching linked pages in the background.
<a> tags).import Link from 'next/link';
<Link href="/target">
Go to Target
</Link>
The <Link> component also has the following properties:
Step 1: To create a new NextJs App run the below command in your terminal:
npx create-next-app GFGStep 2: After creating your project folder (i.e. GFG ), move to it by using the following command:
cd GFGIt will look like this.
👁 ImageAdding 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.
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 devOutput: This will start the development server for your Next.Js application.
👁 ImageHere:
next/link.<Link> to navigate back to the homepage without a full page reload.