|
NextJS is a React framework that is used to build full-stack web applications. It is used both for front-end as well as back-end. It comes with a powerful set of features to simplify the development of React applications. In this article, we will learn about how to add styling to an active link in NextJS. Approach to Add Styling To An Active Link In NextJSWe are going to use a usePathname hook. usePathname hook is a client component hook and it is used to get a current URL’s pathname. By using the ternary operator, we are comparing if the current pathname matches the specified pathname. if it matches the specified pathname then, we are adding an active class name. Syntax: const pathname = usePathname() Steps to Setup a NextJS AppStep 1: Create a NextJS application using the following command and answer a few questions. npx create-next-app@latest app_name Step 2: It will ask you some questions, so choose as the following. √ Would you like to use TypeScript? ... No Step 3: After creating your project folder, move to it using the following command. cd app_name Project Structure:Example: The below example demonstrate the adding of an active link styling in NextJS
Start your application using the command: npm run dev Output: |
Reffered: https://www.geeksforgeeks.org
ReactJS |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 16 |