diff --git a/.changeset/itchy-chefs-give.md b/.changeset/itchy-chefs-give.md new file mode 100644 index 00000000000..1afc35e0ef9 --- /dev/null +++ b/.changeset/itchy-chefs-give.md @@ -0,0 +1,6 @@ +--- +"@remix-run/react": patch +"@remix-run/server-runtime": patch +--- + +fix(singlefetch): handle root path with basename diff --git a/contributors.yml b/contributors.yml index b06d3bbbb05..99b33a6b0cb 100644 --- a/contributors.yml +++ b/contributors.yml @@ -662,6 +662,7 @@ - tascord - TheRealAstoo - therealflyingcoder +- ThisIsAreku - thomasheyenbrock - thomasrettig - thomasverleye diff --git a/packages/remix-react/single-fetch.tsx b/packages/remix-react/single-fetch.tsx index d65b136ec85..7427e67c65d 100644 --- a/packages/remix-react/single-fetch.tsx +++ b/packages/remix-react/single-fetch.tsx @@ -393,6 +393,8 @@ export function singleFetchUrl(reqUrl: URL | string) { if (url.pathname === "/") { url.pathname = "_root.data"; + } else if (url.pathname === window.__remixContext.basename) { + url.pathname = window.__remixContext.basename.concat("_root.data"); } else { url.pathname = `${url.pathname.replace(/\/$/, "")}.data`; } diff --git a/packages/remix-server-runtime/server.ts b/packages/remix-server-runtime/server.ts index 1c730615954..862a55997da 100644 --- a/packages/remix-server-runtime/server.ts +++ b/packages/remix-server-runtime/server.ts @@ -195,7 +195,7 @@ export const createRequestHandler: CreateRequestHandlerFunction = ( let handlerUrl = new URL(request.url); handlerUrl.pathname = handlerUrl.pathname .replace(/\.data$/, "") - .replace(/^\/_root$/, "/"); + .replace(_build.basename ? /\/_root$/ : /^\/_root$/, "/"); let singleFetchMatches = matchServerRoutes( routes,