Skip to content

Commit

Permalink
fix(history): ensure base is normalized in memory history (#1112)
Browse files Browse the repository at this point in the history
  • Loading branch information
david50407 authored Sep 10, 2021
1 parent da7a219 commit 198a5bd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions __tests__/history/memory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
})
2 changes: 2 additions & 0 deletions src/history/memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
NavigationType,
NavigationDirection,
NavigationInformation,
normalizeBase,
createHref,
HistoryLocation,
} from './common'
Expand All @@ -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++
Expand Down

0 comments on commit 198a5bd

Please sign in to comment.