|
Next.js 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. One of its features is redirect Function. In this article, we will learn about redirect Function. The redirect function in Next.js is used to redirect users from one URL to another. It can be used in various contexts such as Server Components, Client Components, Route Handlers and Server Actions. permanentRedirect can either insert a meta tag for client-side redirection or serve an appropriate HTTP redirect status code response. Syntax:import { redirect } from 'next/navigation'; Where:
Steps to Create Next.js ApplicationStep 1: Create a Next.js application using the following command. npx create-next-app@latest gfg 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 i.e. gfg, move to it using the following command. cd gfg Project Structure:Project structure Example: The below example demonstrate the use of redirect function in next.js.
To run the Application open the terminal in the project folder and enter the following command: npm run dev Output: |
Reffered: https://www.geeksforgeeks.org
ReactJS |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 21 |