react路由变化时,index.html引入bundle.js的路径变化

当地址栏为http://localhost:3030/articles时index.html引入的路径为http://localhost:3030/dist/js/bundle.js
当地址栏变为http://localhost:3030/articles/1时,此时刷新一下页面index.html引入的路径就变为http://localhost:3030/articles/dist/js/bundle.js
这种情况下页面就无法加载了,所以这是要如何解决?
webpack的publicPath配置如下

clipboard.png

index.html的引入如下

clipboard.png

阅读 3.1k
1 个回答
<script src="/dist/bundle.js"></script>

publicPath开头加上斜杠

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题