From ce575bbf1a233260cd664dcdc2fd7b4ac07ec7fe Mon Sep 17 00:00:00 2001 From: Tanner Linsley Date: Mon, 7 Aug 2023 15:44:18 -0600 Subject: [PATCH] fix: memory history update --- packages/router/src/history.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/router/src/history.ts b/packages/router/src/history.ts index e8cc4919ca..dec31dc10f 100644 --- a/packages/router/src/history.ts +++ b/packages/router/src/history.ts @@ -45,7 +45,7 @@ const stopBlocking = () => { function createHistory(opts: { getLocation: () => RouterLocation - listener: (onUpdate: () => void) => () => void + listener: false | ((onUpdate: () => void) => () => void) pushState: (path: string, state: any) => void replaceState: (path: string, state: any) => void go: (n: number) => void @@ -72,7 +72,9 @@ function createHistory(opts: { queue.shift()?.() } - // onUpdate() + if (!opts.listener) { + onUpdate() + } } const queueTask = (task: () => void) => { @@ -91,7 +93,10 @@ function createHistory(opts: { }, listen: (cb: () => void) => { if (listeners.size === 0) { - unsub = opts.listener(onUpdate) + unsub = + typeof opts.listener === 'function' + ? opts.listener(onUpdate) + : () => {} } listeners.add(cb) @@ -229,9 +234,7 @@ export function createMemoryHistory( return createHistory({ getLocation, - listener: () => { - return () => {} - }, + listener: false, pushState: (path, state) => { currentState = { ...state,