gpt4 book ai didi

webpack-dev-server historyApiFallback 在多级路由的情况下不起作用

转载 作者:行者123 更新时间:2023-12-05 04:06:59 24 4
gpt4 key购买 nike

我正在使用 historyApiFallback: true 将所有不存在的 url 重定向到索引页面。它适用于一级路由,比如 localhost:8080/abc 。但是当我尝试 localhost:8080/abc/xyz 时,我在浏览器控制台中收到错误

http://localhost:8080/abc/scripts/bundle.js 404 (Not Found)

Webpack 配置是

const path = require('path');

module.exports = {
entry:"./src/app.js",
output:{
path:path.join(__dirname,'public','scripts'),
filename:'bundle.js'
},
module:{
rules:[{
test:/\.js$/,
exclude:/node_modules/,
loader:'babel-loader'
}]
},
devServer:{
contentBase:path.join(__dirname,'public'),
publicPath:'/scripts/',
historyApiFallback: true
}
}

索引页

<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div id="app">
hello
</div>
</body>
<script type="text/javascript" src="scripts/bundle.js"></script>
</html>

文件夹结构是

-node_modules/
-public/
-scripts/
-index.html
-src/
-app.js
-package.json
-webpack.config.js

我错过了什么?

最佳答案

html 中的脚本标记中缺少正斜杠是导致问题的原因。 This帮我解决了问题。

关于webpack-dev-server historyApiFallback 在多级路由的情况下不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49207826/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com