From b8a282e1156559ed923a7d92cd44bcac43f0d1e9 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Tue, 18 Jul 2023 11:03:14 +0100 Subject: [PATCH] fix(nuxt): don't redirect if initial path has trailing slash (#22192) --- packages/nuxt/src/pages/runtime/plugins/router.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/nuxt/src/pages/runtime/plugins/router.ts b/packages/nuxt/src/pages/runtime/plugins/router.ts index 27030a041c..a1aa56f3b8 100644 --- a/packages/nuxt/src/pages/runtime/plugins/router.ts +++ b/packages/nuxt/src/pages/runtime/plugins/router.ts @@ -9,7 +9,7 @@ import { createWebHistory } from '#vue-router' import { createError } from 'h3' -import { withoutBase } from 'ufo' +import { isEqual, withoutBase } from 'ufo' import type { PageMeta, Plugin, RouteMiddleware } from '../../../app/index' import { defineNuxtPlugin, useRuntimeConfig } from '#app/nuxt' @@ -42,7 +42,8 @@ function createCurrentLocation ( if (pathFromHash[0] !== '/') { pathFromHash = '/' + pathFromHash } return withoutBase(pathFromHash, '') } - const path = renderedPath || withoutBase(pathname, base) + const displayedPath = withoutBase(pathname, base) + const path = !renderedPath || isEqual(displayedPath, renderedPath, { trailingSlash: true }) ? displayedPath : renderedPath return path + (path.includes('?') ? '' : search) + hash }