diff --git a/packages/start-server-core/src/createStartHandler.ts b/packages/start-server-core/src/createStartHandler.ts index f2b887b6711..aa2da38cfe0 100644 --- a/packages/start-server-core/src/createStartHandler.ts +++ b/packages/start-server-core/src/createStartHandler.ts @@ -349,9 +349,14 @@ async function handleServerRoutes({ let url = new URL(request.url) url = executeRewriteInput(router.rewrite, url) const pathname = url.pathname + // this will perform a fuzzy match, however for server routes we need an exact match + // if the route is not an exact match, executeRouter will handle rendering the app router + // the match will be cached internally, so no extra work is done during the app router render const { matchedRoutes, foundRoute, routeParams } = router.getMatchedRoutes(pathname) + const isExactMatch = foundRoute && routeParams['**'] === undefined + // TODO: Error handling? What happens when its `throw redirect()` vs `throw new Error()`? const middlewares = flattenMiddlewares( @@ -359,8 +364,7 @@ async function handleServerRoutes({ ).map((d) => d.options.server) const server = foundRoute?.options.server - - if (server) { + if (server && isExactMatch) { if (server.handlers) { const handlers = typeof server.handlers === 'function'