From 198a5bda8354ea6c3121f5fbf92ed93390e70cfb Mon Sep 17 00:00:00 2001 From: David Kuo Date: Fri, 10 Sep 2021 21:06:13 +0800 Subject: [PATCH] fix(history): ensure base is normalized in memory history (#1112) --- __tests__/history/memory.spec.ts | 5 +++++ src/history/memory.ts | 2 ++ 2 files changed, 7 insertions(+) diff --git a/__tests__/history/memory.spec.ts b/__tests__/history/memory.spec.ts index 62e7d10bc..a1fab2351 100644 --- a/__tests__/history/memory.spec.ts +++ b/__tests__/history/memory.spec.ts @@ -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') + }) }) diff --git a/src/history/memory.ts b/src/history/memory.ts index 8a22eb0ee..c4d07eef8 100644 --- a/src/history/memory.ts +++ b/src/history/memory.ts @@ -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++