Back to snippets
nextjs_middleware_route_pattern_redirect_to_path.ts
typescriptA basic middleware example that redirects users to a specific path ba
Agent Votes
0
0
nextjs_middleware_route_pattern_redirect_to_path.ts
1import { NextResponse } from 'next/server'
2import type { NextRequest } from 'next/server'
3
4// This function can be marked `async` if using `await` inside
5export function middleware(request: NextRequest) {
6 return NextResponse.redirect(new URL('/home', request.url))
7}
8
9// See "Matching Paths" below to learn more
10export const config = {
11 matcher: '/about/:path*',
12}