it('should use a correct base', () => {
createWebHashHistory()
// both, a trailing / and none work
- expect(createWebHistory).toHaveBeenCalledWith('/usr/some-file.html#')
+ expect(createWebHistory).toHaveBeenCalledWith('#')
})
})
})
spy.mockRestore()
})
- it('works with file:/// urls and a base', () => {
+ it('calls push with hash part of the url with a base', () => {
dom.reconfigure({ url: 'file:///usr/etc/index.html' })
let history = createWebHistory('/usr/etc/index.html#/')
let spy = jest.spyOn(window.history, 'pushState')
expect(spy).toHaveBeenCalledWith(
expect.anything(),
expect.any(String),
- 'file:///usr/etc/index.html#/foo'
+ '#/foo'
+ )
+ spy.mockRestore()
+ })
+
+ it('works with something after the hash in the base', () => {
+ dom.reconfigure({ url: 'file:///usr/etc/index.html' })
+ let history = createWebHistory('#something')
+ let spy = jest.spyOn(window.history, 'pushState')
+ history.push('/foo')
+ expect(spy).toHaveBeenCalledWith(
+ expect.anything(),
+ expect.any(String),
+ '#something/foo'
)
spy.mockRestore()
})
// Make sure this implementation is fine in terms of encoding, specially for IE11
// for `file://`, directly use the pathname and ignore the base
// location.pathname contains an initial `/` even at the root: `https://example.com`
- base = location.host ? base || location.pathname : location.pathname
+ base = location.host ? base || location.pathname : ''
// allow the user to provide a `#` in the middle: `/base/#/app`
if (base.indexOf('#') < 0) base += '#'
state: StateEntry,
replace: boolean
): void {
+ // when the base has a `#`, only use that for the URL
+ const hashIndex = base.indexOf('#')
const url =
- createBaseLocation() +
- // preserve any existing query when base has a hash
- (base.indexOf('#') > -1 && location.search
- ? location.pathname + location.search + '#'
- : base) +
- to
+ hashIndex > -1
+ ? base.slice(hashIndex) + to
+ : createBaseLocation() + base + to
try {
// BROWSER QUIRK
// NOTE: Safari throws a SecurityError when calling this function 100 times in 30 seconds