From 8d2dd038f6c76132118545ea2e26a30f643af36f Mon Sep 17 00:00:00 2001 From: builde Date: Sat, 7 Sep 2024 23:24:09 +0300 Subject: [PATCH] fix(vue): incorrect view rendered when using router.go(-n) closes #29846 --- packages/vue-router/src/locationHistory.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/vue-router/src/locationHistory.ts b/packages/vue-router/src/locationHistory.ts index f48499254ea..70d6836d59d 100644 --- a/packages/vue-router/src/locationHistory.ts +++ b/packages/vue-router/src/locationHistory.ts @@ -240,7 +240,11 @@ export const createLocationHistory = () => { } } if (delta < -1) { - return locationHistory[locationHistory.length - 1 + delta]; + let routeIndex = locationHistory.findIndex(history => history === routeInfo); + if (routeIndex === -1) { + routeIndex = locationHistory.length - 1; + } + return locationHistory[Math.max(0, routeIndex + delta)]; } else { for (let i = locationHistory.length - 2; i >= 0; i--) { const ri = locationHistory[i];