React Router useRouterHistory interrupts routing

I am developing an application using React and React-Router. I cannot use browserHistory, but must use hashHistory. Just passing ReactRouter.hashHistory to the router history attribute works fine. But since I want to get rid of the request parameter _q, I use useRouterHistory, as described in React-Router Docs . Oddly enough, when I do this, my application stops working completely. It appears that no route is actually called because no markup is created.

Here's what my routes look like and how I begin to respond to the history of routers:

var routes = (
      <Route component={App}>
        <Route path="/" component={Countries} />
        <Route path="/country/:id" component={Country} />
      </Route>
    ),
    useRouterHistory = require('react-router').useRouterHistory,
    createHashHistory = require('history').createHashHistory,
    appHistory = useRouterHistory(createHashHistory)({query: false}),
    routes = require('./routes.jsx');


ReactDOM.render( <Router history={appHistory} routes={routes} />, document.getElementById('app') );

Am I doing it right? Any ideas why the app is not building?

+4

Source: https://habr.com/ru/post/1656955/


All Articles