I'm trying to create a react
app with webpack
which has some routing as well.
"react-router-dom": "^5.2.0",
The routing works but when I go to a specific route and reload the page, it gives an error cannot get /about
import React from "react";
import {
BrowserRouter as Router,
Switch,
Route,
Link
} from "react-router-dom";
export default function App() {
return (
<Router>
<div>
<nav>
<ul>
<li>
<Link to="/">Home</Link>
</li>
<li>
<Link to="/about">About</Link>
</li>
<li>
<Link to="/users">Users</Link>
</li>
</ul>
</nav>
<Switch>
<Route path="/about">
<About />
</Route>
<Route path="/users">
<Users />
</Route>
<Route path="/">
<Home />
</Route>
</Switch>
</div>
</Router>
);
}
function Home() {
return <h2>Home</h2>;
}
function About() {
return <h2>About</h2>;
}
function Users() {
return <h2>Users</h2>;
}
As mentioned in this answer, adding
devServer: {
historyApiFallback: true,
}
fixes the issue when its being run locally, but as soon as I deploy it, I get the same error