Comments (12)
For anyone having this issue, I ended up using @withRouter
like so in my App.jsx
and that seemed to do the trick.
import { Switch, Route, Link, withRouter } from 'react-router-dom';
@inject('store')
@withRouter
@observer
export default class App extends Component {
...
}
from mobx-react-router.
Let me know if there's still issues. New version 4.0.1 is now out.
from mobx-react-router.
I tried <Router history={routingStore.history}>...</Router>
instead of <Router history={history}>...</Router>
and it worked.
from mobx-react-router.
I have a similar issue w/ react-router v4, only I've been trying hashHistory and memoryHistory. Url successfully updates and the Router store gets updated, but the components never re-render. A page refresh then shows the correct component. If I remove the syncHistoryWithStore
and pass the history directly to Router
, everything works as expected.
from mobx-react-router.
Same problem here. As I can see, the original history from history v4.6.1 already has listen
method, and it is overloaded during the syncronisation in the syncHistoryWithStore
function.
from mobx-react-router.
I am having similar issue @mergebandit, have you managed to fix the issue?
from mobx-react-router.
Sorry been away this last week, will take a look soon - seems odd that this simple case would not work.
from mobx-react-router.
Ok I think the issue is fixed, it was an oversight on my part. Changed the listen
function to subscribe
, and also I am now mutating the original history object as opposed to returning enhanced history as a completely new reference - which was causing issues too. PR at #18.
from mobx-react-router.
I'm still having this issue running 4.0.1
I'm pulling my router out of props:
const { router, result } = this.props
calling push:
router.push(`/top-results/${result.id}`)
and here injecting the router store into the component:
inject('router')(observer(TopResult))
For reference, here's my store creation:
import { RouterStore } from 'mobx-react-router'
import appStores from 'store'
let stores = {
router: new RouterStore(),
...appStores,
}
export default stores
And here's where I build my root component:
import React from 'react'
import ReactDOM from 'react-dom'
import { Provider } from 'mobx-react'
import createBrowserHistory from 'history/createBrowserHistory'
import { syncHistoryWithStore } from 'mobx-react-router'
import { BrowserRouter as Router } from 'react-router-dom'
import './index.css'
import stores from './config/store'
import RouteConfig from './config/views'
const browserHistory = createBrowserHistory()
const history = syncHistoryWithStore(browserHistory, stores.router)
ReactDOM.render(
/* Currently having to pass {...stores} as well, so I can just inject('specificStore')
* instead of always inject('store') and then const { specificStore } = this.props.store
*/
<Provider store={stores} {...stores}>
<Router history={history}>
<RouteConfig />
</Router>
</Provider>,
document.getElementById('root')
)
If I just do the following, this works:
import { Link } from 'react-router-dom'
<Link to={`top-results/${result.id}`}>{result.name}</Link>
Finally, here's my mobx-devtools output:
from mobx-react-router.
Ah, I see the issue. You're using the BrowserRouter
component at the top level and trying to pass history to it - but that prop doesn't exist. You need to use the more low-level Router
component from react-router, as shown in the docs.
from mobx-react-router.
@alisd23 Hi I still encounter this issue, would you please help to check?
my-react-starter
const browserHistory = createBrowserHistory()
const routerStore = new RouterStore()
const history = syncHistoryWithStore(browserHistory, routerStore)
history.subscribe((location, action) => console.log(location.pathname));
both browserHistory
and history
do not get update when click Link
to change the path
from mobx-react-router.
Hi @njleonzhang I can't see the code you wrote above in the project you linked me. Just make sure you've followed the documentation and exhausted all options. If it still doesn't work and you're sure it's a bug with this project (which hasn't been addressed already - like this issue), then open an issue. ๐
from mobx-react-router.
Related Issues (20)
- Newly created store missing history and location in react-router 6.x HOT 31
- mobx-react-router/Router not exported HOT 1
- Doc with react-router-v6 is missing.
- Remove support for decorators
- New react-router typings causes mismatch with mobx-react-router HOT 3
- Nested routes HOT 2
- Any way to update a hash route? HOT 1
- .. with Typescript Property 'routing' does not exist on type 'Readonly<{ children?: ReactNode; }> & Readonly<{}> HOT 4
- How to get route params? HOT 4
- update peer dependencies HOT 1
- [question] this vs react-router-dom HOT 1
- n element descriptor's .kind property must be either โmethodโ or โfieldโ HOT 2
- Issue with TypeScript when trying to use SynchronizedHistory from RouterStore HOT 1
- How to send params to other pages? HOT 3
- Compatible with Server Side Rendering? HOT 2
- Update Peer Dependency HOT 3
- Server Side Rendering is broken in v4.0.6 HOT 1
- Pass state with RoutingStore.push() HOT 1
- Looking for maintainers HOT 11
- will v3 with latest mobx? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mobx-react-router.