使用 vue 3 处理 vue-router 参数中的点

Jus*_*ser 4 javascript vue.js vuejs2

如果路由参数包含 dot(.),vue 会将路由重定向到 404。在 vue 2 中,我们可以在 webpack 中使用以下规则允许/处理路由器参数中的点:

devServer: {
      historyApiFallback: {
          disableDotRule: true
      }
 }
Run Code Online (Sandbox Code Playgroud)

但vue 3使用vite而不是webpack。现在如何处理参数中的点?

路线示例如下:

{
  path: your-route/:params",
  component: somecomponent,
}
Run Code Online (Sandbox Code Playgroud)

Jos*_*ras 9

我遇到了同样的问题,根据其中一个问题评论,我去了关于这个问题的 github 问题,他们推荐了一个 vite 插件来解决它。

安装它

npm install --save-dev vite-plugin-rewrite-all
Run Code Online (Sandbox Code Playgroud)

并将其添加到 vite.config.js

import pluginRewriteAll from 'vite-plugin-rewrite-all';

export default {
  plugins: [pluginRewriteAll()]
}
Run Code Online (Sandbox Code Playgroud)

查看 github 问题https://github.com/vitejs/vite/issues/4344

该插件的 github https://github.com/ivesia/vite-plugin-rewrite-all