expect(stripBase('/thing', '')).toBe('/thing')
})
+ it('is case insensitive', () => {
+ expect(stripBase('/Base/foo', '/base')).toBe('/foo')
+ expect(stripBase('/Basé/foo', '/base')).toBe('/Basé/foo')
+ expect(stripBase('/Basé/foo', '/basé')).toBe('/foo')
+ expect(stripBase('/base/foo', '/Base')).toBe('/foo')
+ expect(stripBase('/base/foo', '/Basé')).toBe('/base/foo')
+ expect(stripBase('/basé/foo', '/Basé')).toBe('/foo')
+ })
+
it('returns the pathname without the base', () => {
expect(stripBase('/base', '/base')).toBe('/')
expect(stripBase('/base/', '/base')).toBe('/')
NavigationInformation,
} from './common'
+// TODO: verify base is working for SSR
+
/**
* Creates a in-memory based history. The main purpose of this history is to handle SSR. It starts in a special location that is nowhere.
* It's up to the user to replace that location with the starter location.
}
/**
- * Strips off the base from the beginning of a location.pathname
+ * Strips off the base from the beginning of a location.pathname in a non
+ * case-sensitive way.
*
* @param pathname - location.pathname
* @param base - base to strip off
*/
export function stripBase(pathname: string, base: string): string {
- // no base or base is not found at the begining
- if (!base || pathname.indexOf(base)) return pathname
- return pathname.replace(base, '') || '/'
+ // no base or base is not found at the beginning
+ if (!base || pathname.toLowerCase().indexOf(base.toLowerCase()))
+ return pathname
+ return pathname.slice(base.length) || '/'
}
/**