Skip to content
Discussion options

You must be logged in to vote

The feature you are looking for can be resolved by using the middleware.

It's common to use Middleware for authentication or other purposes that involve rewriting the user to a different page.

Since the middleware runs before a request is completed, it is possible to redirect to the URL by pathname which was directed by the Link component.

Middleware allows you to run code before a request is completed. Then, based on the incoming request, you can modify the response by rewriting, redirecting, modifying the request or response headers, or responding directly.

Example:

// middleware.ts

import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';
 
// Thi…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by trebordng-archive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants