Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sync react-router with mobx state

Is there any way, how can I store react-router state (location, params, etc.) into my appState object as observable property? I am looking for something similar to react-router-redux.

like image 561
David Novák Avatar asked Jun 22 '26 02:06

David Novák


1 Answers

The typical way to do this is to update the store representing your navigation state in the componentWillMount hooks of the routed components. When you do this a lot it doesn't feel really "clean" in the long run. For that reason we ended up not using react-router at all, and just parse routes ourselves (using route-parser). See this blog for the ideas behind it.

Based on the same ideas mobx-router was developed recently, you might give that a spin as well! Or just stick to componentWillMount if your routing is pretty trivial

like image 68
mweststrate Avatar answered Jun 24 '26 16:06

mweststrate



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!