【发布时间】:2021-04-02 06:01:00
【问题描述】:
下面是我的文件结构
webpack.config.js 看起来像下面这样
const path = require("path");
const HtmlWebPackPlugin = require("html-webpack-plugin");
const entryPoint = path.join(__dirname, "src", "index.js");
module.exports = {
entry: entryPoint,
output: {
path: path.join(__dirname, "public"),
filename: "bundle.js",
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
},
},
{
test: /\.css$/,
use: ["style-loader", "css-loader"],
},
],
},
plugins: [
new HtmlWebPackPlugin({
template: path.join(__dirname, "public", "index.html"),
filename: "./index.html",
}),
],
devServer: {
contentBase: path.join(__dirname, "public"),
historyApiFallback: true,
// publicPath: "/dist/",
},
devtool: "source-map",
stats: {
errorDetails: true,
},
};
我不知道为什么它仍然无法正常工作,尽管我已经给出了 historyApiFallback
下面是我的 app.js
当我点击/home 路由时,内容没有改变。
谁能解释一下我还要补充什么
【问题讨论】:
-
也许我的问题听起来很傻,但你有没有把你的
App包裹在BrowserRouter中? -
是的。我已经编辑了问题
-
为每条路由添加
exactprop。 -
我认为你需要使用
render而不是component: reactrouter.com/web/api/Route/render-func
标签: reactjs react-router react-router-dom history react-dom