Make the current page pathname available in middleware on NextRequest #63777
KurtRogers
started this conversation in
Ideas
Replies: 1 comment 2 replies
-
You can simplify the check if your page exist to: const res = NextResponse.next();
if (res.ok) {
return res;
} else {
return NextResponse.redirect('/redirect-path');
} |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Goals
Non-Goals
No response
Background
Somehow managed to implement dynamic redirects by making a strict regex in the matcher and also disabling the next link processing in the
missing
object as recommended by the docs here:https://nextjs.org/docs/app/building-your-application/configuring/content-security-policy
It would've been much easier if I had the current page pathname available to me in Next JS (or some guidance on how to make this available in my project.)
Currently the matcher is doing a good job of ensuring that only the current url is the only item returned. But it isn't as reassuring as I'd like it to be.
Proposal
Provide the current page path in the request object for middleware.
I'd be more than happy to help where I can on this.
Beta Was this translation helpful? Give feedback.
All reactions