]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
fix(history): ensure base is normalized in memory history (#1112)
authorDavid Kuo <me@davy.tw>
Fri, 10 Sep 2021 13:06:13 +0000 (21:06 +0800)
committerGitHub <noreply@github.com>
Fri, 10 Sep 2021 13:06:13 +0000 (15:06 +0200)
__tests__/history/memory.spec.ts
src/history/memory.ts

index 62e7d10bc41e853d082025453cd187ddfb7ffd99..a1fab235114ffc6d030070547ea0d5c545d5792e 100644 (file)
@@ -185,4 +185,9 @@ describe('Memory history', () => {
     history.go(1, false)
     expect(spy).not.toHaveBeenCalled()
   })
+
+  it('handles a non-empty base', () => {
+    expect(createMemoryHistory('/foo/').base).toBe('/foo')
+    expect(createMemoryHistory('/foo').base).toBe('/foo')
+  })
 })
index 8a22eb0ee9e09149929605837de7d03eb6cbda57..c4d07eef8f259edc17107bbacd8bb43575e1d598 100644 (file)
@@ -6,6 +6,7 @@ import {
   NavigationType,
   NavigationDirection,
   NavigationInformation,
+  normalizeBase,
   createHref,
   HistoryLocation,
 } from './common'
@@ -21,6 +22,7 @@ export function createMemoryHistory(base: string = ''): RouterHistory {
   let listeners: NavigationCallback[] = []
   let queue: HistoryLocation[] = [START]
   let position: number = 0
+  base = normalizeBase(base)
 
   function setLocation(location: HistoryLocation) {
     position++