You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What is the improvement or update you wish to see?
Explicit note of a possibility to use the same path matching as in e.g. redirects (source, destination, has, ...) for middleware's matcher and some warning in basePath docs for middleware users
Is there any context that might help us understand?
Not sure if this falls under the category of a bug or it's just missing pieces in the documentation of middleware or testing scenario, but I did struggle for a while to get it fixed - so having it documented would probably help others
The missing piece is an explicit note of a possibility to use the same path matching as in e.g. redirects (source, destination, has, ...) for middleware's matcher
Bumped into this while fixing my problem (bug?) of a combination of having both middleware and basePath set.
The matcher's path matching array, e.g. the one in doc example ('/((?!api|_next/static|_next/image|favicon.ico).*)') works fine until you start deploying the app to a system where basePath is required
It affects only the root route (/) - which may be the most visited (or linked to) route in the entire app - and for both pages and appDir setups
So let's say we have the above matcher setup from docs in middleware
That produces regex '^(?:\/(_next\/data\/[^/]{1,}))?(?:\/((?!api|_next\/static|_next\/image|favicon.ico).*))(.json)?[\/#\?]?$' against which the path is matched, where in case of a undefined basePath root route is '/'
Works as it should
Then if we need basePath updated for deployment to another system this regex is slightly updated
Let's say we use basePath: 'withbase' in next.config.js
then the regex is '^\/withbase(?:\/(_next\/data\/[^/]{1,}))?(?:\/((?!api|_next\/static|_next\/image|favicon.ico).*))(.json)?[\/#\?]?$'
Unfortunately the requested/rendered path is from the server's point of view '/withbase' and that does not match with this regex and/or the required rule 1 of matchers "MUST start with /", which ultimately translates to the '/withbase/' as a new root route
Changing trailingSlash setup has no effect on this matching
So maybe another note in the basePath docs should include a warning for middleware users that matcher needs modification, which for me was
What is the improvement or update you wish to see?
Explicit note of a possibility to use the same path matching as in e.g. redirects (source, destination, has, ...) for middleware's matcher and some warning in basePath docs for middleware users
Is there any context that might help us understand?
Not sure if this falls under the category of a bug or it's just missing pieces in the documentation of middleware or testing scenario, but I did struggle for a while to get it fixed - so having it documented would probably help others
The missing piece is an explicit note of a possibility to use the same path matching as in e.g. redirects (source, destination, has, ...) for middleware's matcher
Bumped into this while fixing my problem (bug?) of a combination of having both middleware and basePath set.
The matcher's path matching array, e.g. the one in doc example (
'/((?!api|_next/static|_next/image|favicon.ico).*)'
) works fine until you start deploying the app to a system where basePath is requiredIt affects only the root route (/) - which may be the most visited (or linked to) route in the entire app - and for both pages and appDir setups
So let's say we have the above matcher setup from docs in middleware
That produces regex
'^(?:\/(_next\/data\/[^/]{1,}))?(?:\/((?!api|_next\/static|_next\/image|favicon.ico).*))(.json)?[\/#\?]?$'
against which the path is matched, where in case of a undefined basePath root route is'/'
Works as it should
Then if we need basePath updated for deployment to another system this regex is slightly updated
Let's say we use
basePath: 'withbase'
in next.config.jsthen the regex is
'^\/withbase(?:\/(_next\/data\/[^/]{1,}))?(?:\/((?!api|_next\/static|_next\/image|favicon.ico).*))(.json)?[\/#\?]?$'
Unfortunately the requested/rendered path is from the server's point of view
'/withbase'
and that does not match with this regex and/or the required rule 1 of matchers "MUST start with /", which ultimately translates to the'/withbase/'
as a new root routeChanging trailingSlash setup has no effect on this matching
So maybe another note in the basePath docs should include a warning for middleware users that matcher needs modification, which for me was
Tested with Next.js up to 13.2.4 (React 18, node v16 and v18)
Does the docs page already exist? Please link to it.
No response
The text was updated successfully, but these errors were encountered: