NextResponse.redirect infinite loop
Unanswered
Entlebucher Mountain Dog posted this in #help-forum
Entlebucher Mountain DogOP
import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'
import { endDate } from './constants';
export function middleware(req: NextRequest) {
const isDateEnded = endDate < new Date()
if (!isDateEnded) {
// after redirecting my /launch page is not found but still my page is found
// how can i fix it without changing the url
return NextResponse.redirect(new URL("/launch", req.url));
}
return NextResponse.next();
}
export const config = {
matcher: ["/((?!api|_next/static|_next/image|favicon.ico|icon.ico).*)"],
}
import type { NextRequest } from 'next/server'
import { endDate } from './constants';
export function middleware(req: NextRequest) {
const isDateEnded = endDate < new Date()
if (!isDateEnded) {
// after redirecting my /launch page is not found but still my page is found
// how can i fix it without changing the url
return NextResponse.redirect(new URL("/launch", req.url));
}
return NextResponse.next();
}
export const config = {
matcher: ["/((?!api|_next/static|_next/image|favicon.ico|icon.ico).*)"],
}
2 Replies
@Entlebucher Mountain Dog import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'
import { endDate } from './constants';
export function middleware(req: NextRequest) {
const isDateEnded = endDate < new Date()
if (!isDateEnded) {
// after redirecting my /launch page is not found but still my page is found
// how can i fix it without changing the url
return NextResponse.redirect(new URL("/launch", req.url));
}
return NextResponse.next();
}
export const config = {
matcher: ["/((?!api|_next/static|_next/image|favicon.ico|icon.ico).*)"],
}
if (req.nextUrl.pathname === "/launch")
return NextResponse.next()need to check if you are in
/launch because you dont want to redirect from /launch to /launch