gpt4 book ai didi

javascript - 刷新 URL 中包含 ID 的页面时找不到bundle.js

转载 作者:行者123 更新时间:2023-12-03 03:30:50 24 4
gpt4 key购买 nike

我遇到了一个问题,我将用户重定向到显示个人资料信息的相应个人资料页面。我们以http://localhost:8080/user/1 为例。当我使用导航栏中的链接重定向用户时,页面已成功呈现,但当我在同一 URL 中刷新页面时(即 http://localhost:8080/user/1 ),我收到错误消息,指出找不到ERROR http://localhost:8080/user/bundle.js。我是 React router v4 的新手,请帮我解决这个问题。提前致谢。

我的 webpack.config.js 是

 var HtmlWebpackPlugin = require('html-webpack-plugin');
var webpack = require('webpack');
var path = require("path");
var config = {
entry: ["./src/index.tsx", 'webpack-dev-server/client?http://localhost:8080'],
plugins: [
new HtmlWebpackPlugin({
template: 'index.ejs',
filename: 'index.html'
}),
],
output: {
path: path.resolve(__dirname, "build"),
filename: "bundle.js"
},
resolve: {
extensions: [".ts", ".tsx", ".js"]
},
devtool: 'source-map',
module: {
rules: [
{ test: /\.tsx?$/, use: 'tslint-loader', enforce: 'pre' },
{ test: /\.tsx?$/, use: ['babel-loader', 'awesome-typescript-loader'] },
{ test: /\.(css|scss)$/, use: ['style-loader', 'css-loader', 'sass-loader'] },
{ test: /.(png|woff(2)?|eot|ttf|svg)(\?[a-z0-9=\.]+)?$/, use: 'url-loader?limit=1024&name=fonts/[name].[ext]' },
{ test: /\.(jpg|jpeg|gif|png)$/, use: 'url-loader?limit=10&mimetype=image/(jpg|jpeg|gif|png)&name=images/[name].[ext]' }
]
},
devServer: {
contentBase: path.join(__dirname, 'build'),
hot: true,
inline: true,
historyApiFallback: true
}
};

module.exports = config;

最佳答案

看起来您需要一个公共(public)(也称为静态)文件夹!这样您的文件将始终可以从相对位置访问。

如果不是作弊的话,here's an answer from another StackOverflow:

webpack.config.js

output: {
// your stuff
publicPath: '/assets/'
}

关于javascript - 刷新 URL 中包含 ID 的页面时找不到bundle.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46108800/

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