Vue 3 - 如何禁用添加尾部斜杠?

Den*_*ler 8 vue.js vue-router vuejs3 vue-router4

问题陈述 Vue 应用程序在加载脚本后更改 URL 并在末尾添加斜杠。这只发生在路径匹配的路由上/

我的服务器配置如下

/game(.*) => Vue 3 App  
anything else => reverse proxy
Run Code Online (Sandbox Code Playgroud)

我的路由器

const routes = [
    {
        path: '/',
        name: 'Home',
        component: () => import('../views/Home.vue'),
    },
    {
        path: '/:pathMatch(.*)',
        component: () => import('../views/NotFound.vue'),
    },
];

const router = createRouter({
    history: createWebHistory('/game/'),
    routes,
    strict: true
});
Run Code Online (Sandbox Code Playgroud)

发生了什么 如果我请求http://localhost/game,地址栏中的 URL 会更改为http://localhost/game/。我不明白为什么会发生这种情况。我确定的是,是 Vue 完成的,而不是服务器。

屏幕

在此输入图像描述

如果我在 URL 中添加其他内容,例如http://localhost/game/notfound,那么斜杠将不会添加到末尾。

UPD 另外,我展示了我的config.vue.js

process.env.VUE_APP_VERSION = require('./package.json').version;

module.exports = {
    publicPath: (process.env.NODE_ENV === 'production' ? '/game' : '/'),
    devServer: {
        proxy: {
            '^/api': {
                target: 'http://app:'+process.env.APP_PORT,
                ws: false,
                changeOrigin: true
            },
        }
    },
    lintOnSave: 'default',
    productionSourceMap: false
};
Run Code Online (Sandbox Code Playgroud)

和内容console.log(process.env)

{
    "NODE_ENV": "production",
    "VUE_APP_ENV": "dev",
    "VUE_APP_VERSION": "1.0.0",
    "BASE_URL": "/game/"
}
Run Code Online (Sandbox Code Playgroud)