Skip to content
Discussion options

You must be logged in to vote

if you run middleware in App routes, not page routes, you will only get Request, not NextRequest. As a result

How do you mean? Middleware is called with NextRequest, which extends Request. So if a function expects Request as a parameter, you can still pass NextRequest, but not vice-versa.

// middleware.ts
import { NextResponse, NextRequest } from 'next/server'

export function middleware(request: NextRequest) {
  console.log(request.nextUrl) // should print an object
  return NextResponse.redirect(new URL('/home', request.url))
}
 

Replies: 1 comment 12 replies

Comment options

You must be logged in to vote
12 replies
@icyJoseph
Comment options

@ryanwooa
Comment options

@icyJoseph
Comment options

@ryanwooa
Comment options

@icyJoseph
Comment options

Answer selected by ryanwooa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants