diff --git a/__tests__/history/memory.spec.ts b/__tests__/history/memory.spec.ts index 4afa14544..62e7d10bc 100644 --- a/__tests__/history/memory.spec.ts +++ b/__tests__/history/memory.spec.ts @@ -152,10 +152,29 @@ describe('Memory history', () => { const spy = jest.fn() history.listen(spy) history.destroy() + history.push('/2') history.go(-1) expect(spy).not.toHaveBeenCalled() }) + it('can be reused after destroy', () => { + const history = createMemoryHistory() + history.push('/1') + history.push('/2') + history.push('/3') + history.go(-1) + + expect(history.location).toBe('/2') + history.destroy() + history.go(-1) + expect(history.location).toBe(START) + history.push('/4') + history.push('/5') + expect(history.location).toBe('/5') + history.go(-1) + expect(history.location).toBe('/4') + }) + it('can avoid listeners with back and forward', () => { const history = createMemoryHistory() const spy = jest.fn() diff --git a/src/history/memory.ts b/src/history/memory.ts index 4187cf771..5a021fbbc 100644 --- a/src/history/memory.ts +++ b/src/history/memory.ts @@ -52,6 +52,7 @@ export function createMemoryHistory(base: string = ''): RouterHistory { const routerHistory: RouterHistory = { // rewritten by Object.defineProperty location: START, + // TODO: should be kept in queue state: {}, base, createHref: createHref.bind(null, base), @@ -75,6 +76,8 @@ export function createMemoryHistory(base: string = ''): RouterHistory { }, destroy() { listeners = [] + queue = [START] + position = 0 }, go(delta, shouldTrigger = true) {