Reputation: 176
Using HashRouter, the route works well in all circumstances but when BrowserRouter is used , it shows error when the page is refreshed.
Here's the code for the Route which I wrapped under HashRouter and BrowserRouter:
<Switch>
<Route exact path="/" component={Home} />
<Route exact path="/trip-detail" component={TripDetail} />
<Route exact path="/booking" component={TripBooking} />
<Redirect to="/" />
</Switch>
Here's the screenshot I get while refreshing:
Upvotes: 1
Views: 1712
Reputation: 176
UPDATE
Thanks @GabrielBleu, Your solution worked like a charm. It was not react router which was creating this error. It was my webpack(server) config which was unknown to get a route to my components.
The only thing I had updated in my webpack config was to add this code
devServer: {
historyApiFallback: {
index: '/',
},
},
Upvotes: 1