-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use with <Link> component with mobx-react-router #19
Comments
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? |
Not really sure. When i add observer to App component with a switch all links stop working in rest of app. 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 :) |
Hmmm... Does the URL change though? Or is it just that the components aren't re-rendering? |
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. 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? |
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? |
Hi |
Ahhh good to hear, no problem 👍 |
having the same problem here, everything works until I make my App an observer. looks like a React-Router / MobX problem |
So MobX might be causing the |
the hack in the link above fixes it, it's an issue with the mobx / react-router combination |
Yep that's a know problem with using MobX/Redux and React in general. Just have to work around it for now. |
Hi i Wonder how to use this with
<Link>
from react routerhttps://reacttraining.com/react-router/web/api/Link
All my Link components seams to stop working after adding mobx-react-router.
The text was updated successfully, but these errors were encountered: