Closed tobeycodes closed 2 months ago
This code would only work client-side. I think we'll eventually need to figure out a proper way to support this within Next.js
export async function AppMiddleware(req: NextRequest) {
...
if (redirectStrategy === 'always' || notFoundStrategy === 'multisite') {
const source = await fetchSource(pathname, sourceUrl || ''); // rename from fetchRedirect
if (redirectStrategy === 'always' && source.location) {
return NextResponse.redirect(redirect.location, redirect.status);
}
if (notFoundStrategy === 'multisite' && source.status === 404) { // not sure if the key is status or not
const parts = request.nextUrl.pathname.split('/');
return NextResponse.rewrite(
new URL(`/_sites/${parts[2]}/404`, request.url),
);
}
}
...
}
@nicholasio This is pseudo code / not tested but could be an opt in idea.
@tobeycodes interesting idea, feels like more of a workaround but could be a viable option for the pages
directory. I think this would be solvable for the app
dir/router based on what I've seen though, so maybe we just want to fully solve this as part of app directory support?
That is fine with me
The Platforms Starter Kit now supports custom 404 pages
With our upcoming release o app router this is now supported inside app router!
404 and 500 pages do not sit under the
_sites/[site]
middleware so do not have access to the query param. The site can be set here with thewindow.location.host
value instead.