ReactJS MobX and react-router v4 issue with url history

99封情书 提交于 2019-12-06 01:30:45

I Solved this issue.

As a router, I Should be Use the Default Router from react-dom, instead of BrowserRouter or HashRouter from react-router-dom as I was using.

Here is example :

import { Router } from 'react-router';
import history                  from './History';


const APP = document.getElementById('app');

render(
    (
        <Provider {...stores} >
            <MuiThemeProvider>
              <Router history={history}>
                  <div>
                    <Routes />
                  </div>
              </Router>
            </MuiThemeProvider>
        </Provider>
    ) , APP);

Also for the history file, here is the code:

import createBrowserHistory from 'history/createBrowserHistory';

const history = createBrowserHistory();
export default  history;

Seems that the problem was in the BrowserRouter or HashRouter since those both keep their own history. It worked for me with default Router from 'react-router'

Did you try using Router.transitionTo ? https://github.com/ReactTraining/react-router/issues/311

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!