Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions packages/router/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,9 @@ export function createPrefixMatcher(prefix: `/${string}`): (pathname: `/${string
end = pathname.length
}

if (!matchesSegment(expected, decode(pathname.slice(start, end)))) {
// `undefined` stands for a param, which needs a non-empty segment.
const segment = decode(pathname.slice(start, end))
if (expected === undefined ? segment === '' : segment !== expected) {
return false
}

Expand Down Expand Up @@ -627,18 +629,17 @@ function matchesCatchAll(
}

for (let i = 0; i < tail.length; i++) {
if (!matchesSegment(tail[i], segments[end + i]!)) {
const expected = tail[i]
const segment = segments[end + i]!
// `undefined` stands for a param, which needs a non-empty segment.
if (expected === undefined ? segment === '' : segment !== expected) {
return false
}
}

return true
}

function matchesSegment(expected: string | undefined, segment: string): boolean {
return expected === undefined ? segment !== '' : segment === expected
}

// `params` is spread only for a param named `__proto__`, not on every pass.
/* oxlint-disable oxc/no-accumulating-spread */
function toParams<T>(route: Route<T>, segments: readonly string[]): Record<string, string> {
Expand Down
Loading