最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Attempting to route a URL with a dot leads to 404 with webpack dev server - Stack Overflow

programmeradmin9浏览0评论

I'm using Webpack's dev server for ease of local development. I'm working on a single page app, so I've enabled historyApiFallback:

mon.devServer = {
  outputPath: path.join(__dirname, 'www', outDir),
  historyApiFallback: true
};

However, whenever I try to browse to a url that contains a period (such as /ui/alerts/map.postplay), I get

Cannot GET /ui/alerts/map.postplay

How can I convince webpack-dev-server to let me use these urls?

I'm using Webpack's dev server for ease of local development. I'm working on a single page app, so I've enabled historyApiFallback:

mon.devServer = {
  outputPath: path.join(__dirname, 'www', outDir),
  historyApiFallback: true
};

However, whenever I try to browse to a url that contains a period (such as /ui/alerts/map.postplay), I get

Cannot GET /ui/alerts/map.postplay

How can I convince webpack-dev-server to let me use these urls?

Share Improve this question asked Jul 25, 2016 at 19:57 SomeKittensSomeKittens 39.5k19 gold badges116 silver badges145 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 21

UPDATE: You can now just set historyApiFallback to:

historyApiFallback: {
  disableDotRule: true
}

(thanks to BenR for fixing this!)

The trouble lies not in webpack-dev-server but the historyApiFallback config itself (technically, Webpack uses connect-history-api-fallback). There's a known bug relating to URLs with periods.

You can update the config for historyApiFallback to rewrite all urls containing periods:

historyApiFallback: {
  rewrites: [
    {from: /\./, to: '/'}
  ]
}

Since this operates on req.url, you should be fine even if you're doing local dev on something other than localhost via the hosts file, etc.

发布评论

评论列表(0)

  1. 暂无评论