N
N
Nikolay Matyushkin2020-01-19 17:21:37
React
Nikolay Matyushkin, 2020-01-19 17:21:37

What is the problem when using BrowserRouter and getting 404 error?

Hello! Point me to the right path, I beg you.
There is a project .
Used HashRouter to route my application. Everything would be fine, but the lattice in the url began to strain. I changed it to BrowserRouter, besides, the specifics of the application are similar to the situation when, judging by the titorial , it is necessary to use the BrowserRouter (a dynamic application with asynchronous requests to a third-party API).
The root element looks like this:

<Provider store={store}>
    <BrowserRouter basename={"/"}>
      <App />
    </BrowserRouter>
  </Provider>

router looks like this:
<Switch>
            <Route exact path="/" component={Menu}/>
            <Route path="/delivery" component={Delivery} />
            <Route path="/pay" component={Pay} />
            <Route path="/about" component={About} />
            <Route path="/manager" component={Manager} />
            <Route path="/personal" component={Personal} />
            <Route component={NotFound} />
          </Switch>

So, having redone it, I got the following: I go through the default route "/" everything is ok. I reboot the page - everything is ok. Then I go along the "/delivery" route - everything is ok. Reboot page - 404 error. And so it is with the rest. When you try to get to the site, for example, at so-dev.tk/delivery , the same thing happens. When you try to register the route manually on the command line - the same 404 error. In fact, routes are only available through programmatic interaction (links). With HashRouter everything works perfectly.
I could leave HashRouter as well, but it became extremely interesting why BrowserRouter behaves this way. On local, by the way, BrowserRouter works well.
Thanks in advance for your replies.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question