繁体   English   中英

webpack-dev-server historyApiFallback 不起作用

[英]webpack-dev-server historyApiFallback doesn't work

我正在尝试实现我的客户端渲染版本。 因此,我想处理从index.html导入的router.js路由。

所以我添加了一个historyAPIFallback但它似乎不起作用。

我尝试了两种方法都指向localhost/post/1/test

  1. 来自官方指南
// webpack.config.js
devServer: {
    port: 3000,
    historyApiFallback: {
      rewrites: [{ from: /.*/, to: './src/index.html' }],
    },
  },

这输出:

Uncaught SyntaxError: Unexpected token '<'

指向第一个<html>标签。

  1. 来自stackoverflow(这似乎是一个旧的解决方案)
// webpack.config.js
devServer: {
    port: 3000,
    historyApiFallback: {
      index: './src/index.html',
    },
  },

这输出:

GET http://localhost:3000/post/1/index.js net::ERR_ABORTED 404 (Not Found)

任何想法来解决我做错了什么?

对我index.html解决方案是在我导入index.js index.html中添加/

前:

<script src="index.js"></script>

后:

<script src="/index.js"></script>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM