Answer the question
In order to leave comments, you need to log in
Why am I getting the error: GET localhost:8080/1/bundle.js net::ERR_ABORTED 404 (Not Found)?
If you specify a non-existent albeit with one slash, for example: localhost:8080/1 , then everything is correct and the page that is indicated with an error 404 through <Route path="*" render={() => <Error404 />} />
A is shown if you specify a path with two or more slashes, for example: localhost:8080/1/1 , then nothing is displayed and the following error appears in the console:
GET http://localhost:8080/1/bundle.js net::ERR_ABORTED 404 (Not Found)
GET http://localhost:8080/user/bundle.js net::ERR_ABORTED 404 (Not Found)
const webpack = require('webpack');
const path = require('path');
const config = {
entry: [
'react-hot-loader/patch',
'./src/index.js'
],
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js',
publicPath: '/'
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
use: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.css$/,
use: [
'style-loader',
'css-loader'
]
},
{
test: /\.svg$/,
use: 'file-loader'
},
{
test: /\.png$/,
use: [
{
loader: 'url-loader',
options: {
mimetype: 'image/png'
}
}
]
}
]
},
resolve: {
extensions: [
'.js',
'.jsx'
],
alias: {
'react-dom': '@hot-loader/react-dom'
}
},
devServer: {
historyApiFallback: true,
contentBase: './dist'
}
};
module.exports = config;
import React from "react";
import { render } from "react-dom";
import { BrowserRouter } from 'react-router-dom';
import App from "./components/App";
import "./index.css";
render(
<React.StrictMode>
<BrowserRouter>
<App />
</BrowserRouter>
</React.StrictMode>,
document.getElementById('app')
);
Answer the question
In order to leave comments, you need to log in
webpack.config.js
const webpack = require('webpack');
const path = require('path');
const config = {
entry: [
'react-hot-loader/patch',
path.resolve(__dirname, 'src', 'index.js')
],
output: {
path: path.resolve(__dirname, './dist'),
filename: 'bundle.js',
publicPath: '/'
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
use: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.css$/,
use: [
'style-loader',
'css-loader'
]
},
{
test: /\.svg$/,
use: 'file-loader'
},
{
test: /\.png$/,
use: [
{
loader: 'url-loader',
options: {
mimetype: 'image/png'
}
}
]
}
]
},
resolve: {
extensions: [
'.js',
'.jsx'
],
alias: {
'react-dom': '@hot-loader/react-dom'
}
},
devServer: {
historyApiFallback: true,
contentBase: path.resolve(__dirname, './dist'),
open: true,
hot: true,
compress: true,
}
};
module.exports = config;
<!DOCTYPE html>
<html>
<head>
<title>example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div id="app"></div>
<script src='../bundle.js'></script>
</body>
</html>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question