From e6594b6f9a38f7be4f78e71d1e5da7ff5e52260d Mon Sep 17 00:00:00 2001 From: echo <1558449520@qq.com> Date: Tue, 5 Sep 2023 00:13:36 +0800 Subject: [PATCH] refactor(memory): reduce duplicate 'queue.push' (#1973) --- packages/router/src/history/memory.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/router/src/history/memory.ts b/packages/router/src/history/memory.ts index c2ec8194c..f8f25a08c 100644 --- a/packages/router/src/history/memory.ts +++ b/packages/router/src/history/memory.ts @@ -26,14 +26,11 @@ export function createMemoryHistory(base: string = ''): RouterHistory { function setLocation(location: HistoryLocation) { position++ - if (position === queue.length) { - // we are at the end, we can simply append a new entry - queue.push(location) - } else { + if (position !== queue.length) { // we are in the middle, we remove everything from here in the queue queue.splice(position) - queue.push(location) } + queue.push(location) } function triggerListeners(