File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -244,6 +244,38 @@ describe("a router", () => {
244
244
} ) ;
245
245
} ) ;
246
246
247
+ it ( "supports a basename prop for route matching and make sure it has a leading /" , async ( ) => {
248
+ let history = createMemoryHistory ( {
249
+ initialEntries : [ "/base/name/path" ] ,
250
+ } ) ;
251
+ let router = createRouter ( {
252
+ basename : "base/name" ,
253
+ routes : [ { path : "path" } ] ,
254
+ history,
255
+ } ) ;
256
+ expect ( router . state ) . toMatchObject ( {
257
+ location : {
258
+ hash : "" ,
259
+ key : expect . any ( String ) ,
260
+ pathname : "/base/name/path" ,
261
+ search : "" ,
262
+ state : null ,
263
+ } ,
264
+ matches : [
265
+ {
266
+ params : { } ,
267
+ pathname : "/path" ,
268
+ pathnameBase : "/path" ,
269
+ route : {
270
+ id : "0" ,
271
+ path : "path" ,
272
+ } ,
273
+ } ,
274
+ ] ,
275
+ initialized : true ,
276
+ } ) ;
277
+ } ) ;
278
+
247
279
it ( "supports subscribers" , async ( ) => {
248
280
let history = createMemoryHistory ( { initialEntries : [ "/" ] } ) ;
249
281
let count = 0 ;
Original file line number Diff line number Diff line change @@ -773,7 +773,8 @@ export function createRouter(init: RouterInit): Router {
773
773
manifest
774
774
) ;
775
775
let inFlightDataRoutes : AgnosticDataRouteObject [ ] | undefined ;
776
- let basename = init . basename || "/" ;
776
+ // make sure it has a leading /
777
+ let basename = init . basename ?. replace ( / ^ \/ * / , "/" ) || "/" ;
777
778
let dataStrategyImpl = init . unstable_dataStrategy || defaultDataStrategy ;
778
779
// Config driven behavior flags
779
780
let future : FutureConfig = {
You can’t perform that action at this time.
0 commit comments