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

為{幸葍}努か 提交于 2019-12-08 06:24:24

问题


I bootstrapped my application from webpack template and added the route /edit/:filename to it.

The problem is, filenames containing a dot are handled by Express and not by my Vue application.

In other words, /edit/123 is matched by the route but /edit/123.json or /edit/123.txt is not and I get a 404 from Express.

How can I match anything or at least /edit/anyfilename.json in my route?


回答1:


I had an answer from Linus Borg on Vue forum. Vue webpack template uses connect-history-api-fallback to redirect all HTTP requests to index.html. It skips HTTP requests with a dot in the path unless disableDotRule is set to true. The proper config is

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

Notice that we have to add an extra rewrite to /app.js so that it is not redirected to index.html.



来源:https://stackoverflow.com/questions/45280091/vue-router-does-not-catch-routes-with-a-dot-in-the-webpack-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!