D
D
Denoro552018-10-15 11:49:45
Node.js
Denoro55, 2018-10-15 11:49:45

How to render the desired page in React with BrowserRouter?

Hello. Such a problem. The task is to make the url without # . I am using browser router. But if you refresh the page, it doesn't find it. She starts to request it on the server. So here's how to direct the response to the desired page so that it can be rendered on Node (express) if I have one, it's just that the routes are on others.

import { Switch , BrowserRouter , Route, Router} from 'react-router-dom';
ReactDOM.render(
  <Provider store={store}>
    <BrowserRouter>
            <div>
                <Switch>
                    <Route exact path="/" component={App}></Route>
                    <Route exact path="/blog" component={Blog}></Route>
                    <Route exact path="/login" component={Login}></Route>
                    <Route exact path="/register" component={Register}></Route>
                    <Route exact path="/chat" component={Chat}></Route>
                    <Route exact path="/user/:id" component={Profile}></Route>
                    <Route component={Err}></Route>
                </Switch>
            </div>
        </BrowserRouter>
    </Provider>,
  document.getElementById('root')
);

And on the main page, for some reason, the grating is localhost:3000/#

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