// ensure leading slash when it was removed by the regex above avoid leading
// slash with hash because the file could be read from the disk like file://
// and the leading slash would cause problems
- if (base.charAt(0) !== '/' && base.charAt(0) !== '#') base = '/' + base
+ if (base[0] !== '/' && base[0] !== '#') base = '/' + base
// remove the trailing slash so all other method can just do `base + fullPath`
// to build an href
if (hashPos > -1) {
// prepend the starting slash to hash so the url starts with /#
let pathFromHash = hash.slice(1)
- if (pathFromHash.charAt(0) !== '/') pathFromHash = '/' + pathFromHash
+ if (pathFromHash[0] !== '/') pathFromHash = '/' + pathFromHash
return normalizeHistoryLocation(stripBase(pathFromHash, ''))
}
const path = stripBase(pathname, base)
* @param base - base to strip off
*/
export function stripBase(pathname: string, base: string): string {
- if (!base || pathname.indexOf(base) !== 0) return pathname
+ // no base or base is not found at the begining
+ if (!base || pathname.indexOf(base)) return pathname
return pathname.replace(base, '') || '/'
}