Redirecting in middleware changes the URL but does not trigger rendering of the new content
Unanswered
GuitarNerd posted this in #help-forum
Hello. I'm using the latest Next with the app directory. My middleware is sometimes changing the URL but not actually rendering the content.
Here is the relevant part of my middleware. Initially i thought it could be the next.config.js rewrites but i disabled them and i still have teh same issue
Here is the relevant part of my middleware. Initially i thought it could be the next.config.js rewrites but i disabled them and i still have teh same issue
if (!isLoggedIn) {
url.pathname = '/login';
return NextResponse.redirect(url);
}
export const config = {
matcher: [
'/((?!api|_next/static|_next/image|favicon.ico|images).*)',
]
}6 Replies
European sprat
Have you tried this?
return NextResponse.redirect(new URL('/login', request.url))@European sprat no i thought that's unnecessary because i'm already cloning the url object but i'll do that and check
@European sprat yeah i just did, didn't solve it
European sprat
Show the rest of the middleware
@European sprat