Hey!
Already solved this a couple different ways on earlier versions of NextJS, but seems that this undocumented behavior still changes from time to time… And now more recently updating to 15.5.3 seems like it changed once again… The Vercel Support team also wasn’t able to find any workarounds for it.
We have some projects that has basePath configured. But on Vercel and Github the links to the Preview environment always go to the “root” path under that preview domain. So you ALWAYS get a 404 when you have a basePath configured.
I would like to redirect the accesses to the Preview environment root path, to the basePath. For example the link on Vercel/Github is https://something.preview.vercel.app/, and it should redirect to https://something.preview.vercel.app/my-custom-base-path.
In past versions I was already able to solve it using the middleware, which doesn’t seem to work anymore.
And also explored trying to catch that with some special next.config.js redirects, or some custom client side logic on the not-found.tsx.
Any other ideas on how to solve this?
I find it a stressful DX for the team, that sometimes is working on a project that they are not super familiar with, and get a 404 on the preview environment, and takes some time to realize that the basePath is missing on the URL. I would love to get them smartly directed to the correct path.