File tree 3 files changed +30
-4
lines changed
3 files changed +30
-4
lines changed Original file line number Diff line number Diff line change 122
122
},
123
123
{
124
124
"path" : " dist/production/navigation.react-client.js" ,
125
- "limit" : " 2.94 KB"
125
+ "limit" : " 2.96 KB"
126
126
},
127
127
{
128
128
"path" : " dist/production/navigation.react-server.js" ,
129
- "limit" : " 3.03 KB"
129
+ "limit" : " 3.06 KB"
130
130
},
131
131
{
132
132
"path" : " dist/production/server.react-client.js" ,
Original file line number Diff line number Diff line change @@ -180,6 +180,13 @@ export function getRoute<Locales extends AllLocales>({
180
180
return template as keyof Pathnames < Locales > ;
181
181
}
182
182
183
- export function getBasePath ( pathname : string ) {
184
- return window . location . pathname . replace ( pathname , '' ) ;
183
+ export function getBasePath (
184
+ pathname : string ,
185
+ windowPathname = window . location . pathname
186
+ ) {
187
+ if ( pathname === '/' ) {
188
+ return windowPathname ;
189
+ } else {
190
+ return windowPathname . replace ( pathname , '' ) ;
191
+ }
185
192
}
Original file line number Diff line number Diff line change 1
1
import { describe , expect , it } from 'vitest' ;
2
2
import {
3
3
compileLocalizedPathname ,
4
+ getBasePath ,
4
5
serializeSearchParams
5
6
} from '../../../src/navigation/shared/utils' ;
6
7
@@ -42,3 +43,21 @@ describe('compileLocalizedPathname', () => {
42
43
) ;
43
44
} ) ;
44
45
} ) ;
46
+
47
+ describe ( 'getBasePath' , ( ) => {
48
+ it ( 'detects a base path when using a locale prefix and the user is at the root' , ( ) => {
49
+ expect ( getBasePath ( '/en' , '/base/en' ) ) . toBe ( '/base' ) ;
50
+ } ) ;
51
+
52
+ it ( 'detects a base path when using a locale prefix and the user is at a nested path' , ( ) => {
53
+ expect ( getBasePath ( '/en/about' , '/base/en/about' ) ) . toBe ( '/base' ) ;
54
+ } ) ;
55
+
56
+ it ( 'detects a base path when using no locale prefix and the user is at the root' , ( ) => {
57
+ expect ( getBasePath ( '/' , '/base' ) ) . toBe ( '/base' ) ;
58
+ } ) ;
59
+
60
+ it ( 'detects a base path when using no locale prefix and the user is at a nested path' , ( ) => {
61
+ expect ( getBasePath ( '/about' , '/base/about' ) ) . toBe ( '/base' ) ;
62
+ } ) ;
63
+ } ) ;
You can’t perform that action at this time.
0 commit comments