Skip to content

Commit f6fcb1b

Browse files
fix: correctly replace bracked escaped part (#4968)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Bug Fixes** - Routing now correctly handles bracketed dynamic segments with multiple characters in paths. Contents like [userId] are preserved in full (no longer truncated to a single character), ensuring accurate initial route generation and consistent navigation behavior for dynamic routes. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 74be286 commit f6fcb1b

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

packages/router-generator/src/utils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ export function removeTrailingSlash(s: string) {
5252
return s.replace(/\/$/, '')
5353
}
5454

55+
const BRACKET_CONTENT_RE = /\[(.*?)\]/g
56+
5557
export function determineInitialRoutePath(routePath: string) {
5658
const DISALLOWED_ESCAPE_CHARS = new Set([
5759
'/',
@@ -73,7 +75,6 @@ export function determineInitialRoutePath(routePath: string) {
7375
// Escape any characters that in square brackets
7476
const escapedParts = parts.map((part) => {
7577
// Check if any disallowed characters are used in brackets
76-
const BRACKET_CONTENT_RE = /\[(.*?)\]/g
7778

7879
let match
7980
while ((match = BRACKET_CONTENT_RE.exec(part)) !== null) {
@@ -91,7 +92,7 @@ export function determineInitialRoutePath(routePath: string) {
9192

9293
// Since this split segment is safe at this point, we can
9394
// remove the brackets and replace them with the content inside
94-
return part.replace(/\[(.)\]/g, '$1')
95+
return part.replace(BRACKET_CONTENT_RE, '$1')
9596
})
9697

9798
// If the syntax for prefix/suffix is different, from the path

0 commit comments

Comments
 (0)