From fc4e3bebe52ec54bbe697abc83e24a2b41c6fca9 Mon Sep 17 00:00:00 2001 From: Luffy <52o@qq52o.cn> Date: Tue, 14 Jan 2025 14:16:33 +0800 Subject: [PATCH] fix: handle query parameters in getFileName method --- src/core/router/history/base.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/core/router/history/base.js b/src/core/router/history/base.js index 268cbb1f4..c52fe5f8a 100644 --- a/src/core/router/history/base.js +++ b/src/core/router/history/base.js @@ -1,10 +1,10 @@ import { + cleanPath, getPath, isAbsolutePath, - stringifyQuery, - cleanPath, replaceSlug, resolvePath, + stringifyQuery, } from '../util.js'; import { noop } from '../../util/core.js'; @@ -32,11 +32,17 @@ export class History { } #getFileName(path, ext) { - return new RegExp(`\\.(${ext.replace(/^\./, '')}|html)$`, 'g').test(path) - ? path - : /\/$/g.test(path) - ? `${path}README${ext}` - : `${path}${ext}`; + const [basePath, query] = path.split("?"); + + const hasValidExt = new RegExp(`\\.(${ext.replace(/^\./, '')}|html)$`, 'g').test(basePath); + + const updatedPath = hasValidExt + ? basePath + : /\/$/g.test(basePath) + ? `${basePath}README${ext}` + : `${basePath}${ext}`; + + return query ? `${updatedPath}?${query}` : updatedPath; } getBasePath() {