Vue-router 不捕获 webpack 模板中带点的路由

Vue-router does not catch routes with a dot in the webpack template

我从 webpack template 启动了我的应用程序并向其添加了路由 /edit/:filename

问题是,包含点的文件名由 Express 而不是我的 Vue 应用程序处理。

换句话说,/edit/123 与路由匹配,但 /edit/123.json/edit/123.txt 不匹配,我从 Express 收到 404。

我怎样才能在我的路线中匹配任何东西或至少 /edit/anyfilename.json

我有一个 answer from Linus Borg on Vue forum. Vue webpack template 使用 connect-history-api-fallback 将所有 HTTP 请求重定向到 index.html。它会跳过路径中带点的 HTTP 请求,除非 disableDotRule 设置为 true。正确的配置是

app.use(require('connect-history-api-fallback')({
  disableDotRule: true,
  rewrites: [
    {from: /\/app.js/, to: '/app.js'}
  ]
}))

请注意,我们必须向 /app.js 添加额外的重写,以便它不会重定向到 index.html