fix(nuxt): don't redirect if initial path has trailing slash (#22192)

This commit is contained in:
Daniel Roe 2023-07-18 11:03:14 +01:00 committed by GitHub
parent fed5868184
commit b8a282e115
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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
}