I know I'm not the only one facing this issue but after searching the web for a while and trying out everything it gave me, I gotta ask for my case here.
I'm getting the popular error that I receive a 404 whenever I try to access a route of my app, when not using an app-related way. So for example if I refresh my page when I'm at "/map", it says "Cannot get /map".
This is my current configuration, although I tried several ones with different devServer: {} settings and playing with publicPath etc.:
webpack.config.js:
const path = require("path");
module.exports = {
entry: "./src/index.js",
output: {
filename: "bundle.js",
path: path.resolve(__dirname, "dist"),
publicPath: "dist"
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: "babel-loader"
}
]
},
devServer: {
historyApiFallback: {
index: "dist/index.html"
}
}
};
App.js
import React, { Component } from "react";
import { connect } from "react-redux";
import { BrowserRouter, Route } from "react-router-dom";
import Homescreen from "./Homescreen";
import Map from "./Map";
import { withStyles } from "material-ui/styles";
import Reboot from "material-ui/Reboot";
import AppBar from "material-ui/AppBar";
import Toolbar from "material-ui/Toolbar";
import Typography from "material-ui/Typography";
import Button from "material-ui/Button";
import IconButton from "material-ui/IconButton";
import MenuIcon from "material-ui-icons/Menu";
const styles = {
flex: {
flex: 1
},
menuButton: {
marginLeft: -3,
marginRight: 20
}
};
class App extends Component {
render() {
const { classes } = this.props;
return (
<BrowserRouter>
<div>
<Reboot />
<AppBar position="sticky">
<Toolbar>
<IconButton className={classes.menuButton} color="inherit" aria-label="Menu">
<MenuIcon />
</IconButton>
<Typography variant="title" color="inherit" className={classes.flex}>
WeltRaum 31
</Typography>
<Button color="inherit">Login</Button>
</Toolbar>
</AppBar>
<Route exact path="/" component={Homescreen} />
<Route path="/map" component={Map} />
</div>
</BrowserRouter>
);
}
};
export default withStyles(styles)(App);