Skip to content

Commit 348d19e

Browse files
fix: handle server routes with exact match
1 parent 64dea9d commit 348d19e

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

packages/start-server-core/src/createStartHandler.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,18 +349,22 @@ async function handleServerRoutes({
349349
let url = new URL(request.url)
350350
url = executeRewriteInput(router.rewrite, url)
351351
const pathname = url.pathname
352+
// this will perform a fuzzy match, however for server routes we need an exact match
353+
// if the route is not an exact match, executeRouter will handle rendering the app router
354+
// the match will be cached internally, so no extra work is done during the app router render
352355
const { matchedRoutes, foundRoute, routeParams } =
353356
router.getMatchedRoutes(pathname)
354357

358+
const isExactMatch = foundRoute && routeParams['**'] === undefined
359+
355360
// TODO: Error handling? What happens when its `throw redirect()` vs `throw new Error()`?
356361

357362
const middlewares = flattenMiddlewares(
358363
matchedRoutes.flatMap((r) => r.options.server?.middleware).filter(Boolean),
359364
).map((d) => d.options.server)
360365

361366
const server = foundRoute?.options.server
362-
363-
if (server) {
367+
if (server && isExactMatch) {
364368
if (server.handlers) {
365369
const handlers =
366370
typeof server.handlers === 'function'

0 commit comments

Comments
 (0)