Skip to content

Commit 9ea0f93

Browse files
committed
some corrections
1 parent 715c881 commit 9ea0f93

3 files changed

Lines changed: 26 additions & 20 deletions

File tree

‎e2e/react-router/basepath-file-based/src/routes/index.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function App() {
2828
})
2929
}
3030
>
31-
Navigate to /redirect with document reload
31+
Navigate to /redirect
3232
</button>
3333
</div>
3434
)

‎packages/router-core/src/rewrite.ts‎

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,30 +36,36 @@ export function rewriteBasepath(opts: {
3636
? normalizedBasepathWithSlash
3737
: normalizedBasepathWithSlash.toLowerCase()
3838

39+
const removeBasePath = (pathname: string) => {
40+
const normalizedPath = opts.caseSensitive
41+
? pathname
42+
: pathname.toLowerCase()
43+
44+
// Handle exact basepath match (e.g., /my-app -> /)
45+
if (normalizedPath === checkBasepath) {
46+
return '/'
47+
}
48+
49+
if (normalizedPath.startsWith(checkBasepathWithSlash)) {
50+
// Handle basepath with trailing content (e.g., /my-app/users -> /users)
51+
return pathname.slice(normalizedBasepath.length)
52+
}
53+
54+
return pathname
55+
}
56+
3957
return {
4058
input: ({ url }) => {
41-
const pathname = opts.caseSensitive
42-
? url.pathname
43-
: url.pathname.toLowerCase()
59+
url.pathname = removeBasePath(url.pathname)
4460

45-
// Handle exact basepath match (e.g., /my-app -> /)
46-
if (pathname === checkBasepath) {
47-
url.pathname = '/'
48-
} else if (pathname.startsWith(checkBasepathWithSlash)) {
49-
// Handle basepath with trailing content (e.g., /my-app/users -> /users)
50-
url.pathname = url.pathname.slice(normalizedBasepath.length)
51-
}
5261
return url
5362
},
5463
output: ({ url }) => {
55-
if (url.pathname === checkBasepath) {
56-
url.pathname = '/'
57-
} else if (url.pathname.startsWith(checkBasepathWithSlash)) {
58-
// Handle basepath with trailing content (e.g., /my-app/users -> /users)
59-
url.pathname = url.pathname.slice(normalizedBasepath.length)
60-
}
61-
62-
url.pathname = joinPaths(['/', trimmedBasepath, url.pathname])
64+
url.pathname = joinPaths([
65+
'/',
66+
trimmedBasepath,
67+
removeBasePath(url.pathname),
68+
])
6369

6470
return url
6571
},

‎packages/router-core/src/router.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1758,7 +1758,7 @@ export class RouterCore<
17581758

17591759
// If a rewrite function is provided, use it to rewrite the URL
17601760
const rewrittenUrl = executeRewriteOutput(this.rewrite, url)
1761-
const rewrittenFullPath = `${rewrittenUrl.pathname}${searchStr}${hashStr}`
1761+
const rewrittenFullPath = `${rewrittenUrl.pathname}${rewrittenUrl.search}${rewrittenUrl.hash}`
17621762

17631763
return {
17641764
publicHref: rewrittenFullPath,

0 commit comments

Comments
 (0)