Comments (11)
I'm not sure, that sounds weird... I defintely tried it with a Link, and it seemed to work fine.
Can you be more specific on what's not working?
from mobx-react-router.
Not really sure. When i add observer to App component with a switch all links stop working in rest of app.
It also seems like location/history is not synced right.
const browserHistory = createHistory();
const routingStore = new RouterStore();
const stores = {
routing: routingStore,
generalStore,
postStore,
};
const history = syncHistoryWithStore(browserHistory, routingStore);
const Root = () => (
<Provider {...stores}>
<Router history={history}>
<App />
</Router>
</Provider>
);
ReactDOM.render(
<Root />,
document.getElementById('root'),
);
@inject('routing')
@observer
export default class App extends Component {
render() {
return (
<div id={'reactroot'}>
{ process.env.NODE_ENV === 'production' ? null : <DevTools /> }
<Switch>
<CenteredLayout exact path="/" component={Start} />
<CenteredLayout exact path="/t/:tSlug" component={CampaignPage} />
<EmptyLayout exact path="/t/:tSlug/sign-up" component={CampaignSignUp} />
<CenteredLayout exact path="/t" component={CampaignList} />
<CenteredLayout component={BasicPage} />
</Switch>
</div>
);
};
}
Something fishy is going on :)
from mobx-react-router.
Hmmm... Does the URL change though? Or is it just that the components aren't re-rendering?
from mobx-react-router.
If i add observer on the app component all links stops working. They are located further down the component tree.
If I don't have the observer and compare Provider, BrowserRouter and Router Components when I click a link thats changes the url in header and renders the new page fine.
In Provider RouterStore location pathname does not change and keeps old url/page.
In BrowserRouter history location does not change and keeps old url/page.
In Router history location pathname do change to the new page :)
So it seems like it do not trigger to sync the store from the router.
Do i need to add inject/observer in every component thats has a Link or Route?
from mobx-react-router.
No you definitely shouldn't have to... I'm still a bit confused. Does the App component render. And does the url in the browser url bar update?
from mobx-react-router.
Hi
Thx for answering.
Regarding history this was a duplicate of #16.
Still not sure why links freezes when adding observer on App component.
from mobx-react-router.
Ahhh good to hear, no problem π
from mobx-react-router.
having the same problem here, everything works until I make my App an observer.
path changes but no component re-render
looks like a React-Router / MobX problem
remix-run/react-router#4781 (comment)
from mobx-react-router.
So MobX might be causing the App
to not re-render because of it implementing shouldComponentUpdate
, blocking the router update if props haven't changed. However this library should fix that problem. If you do some debugging and have more info, let me know - just in case it is an issue with this library.
from mobx-react-router.
the hack in the link above fixes it, it's an issue with the mobx / react-router combination
from mobx-react-router.
Yep that's a know problem with using MobX/Redux and React in general. Just have to work around it for now.
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.