@@ -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 } ,
0 commit comments