Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(history): ensure base is normalized in memory history #1112

Merged
merged 1 commit into from Sep 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions __tests__/history/memory.spec.ts
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
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