acdlite / redux-router

Redux bindings for React Router – keep your router state inside your Redux store
MIT License
2.3k stars 200 forks source link

Why not just integrate with react-router? #96

Closed jadbaz closed 9 years ago

jadbaz commented 9 years ago

I understand the motivation but my why is it necessary to introduce a completely different router package instead of a set of bindings for react-router a-la react-redux? I think it would make sense since react-router is quite mature and very well documented.

chentsulin commented 9 years ago

It's not a completely different router package. redux-router usually work with react-router, and let you easily integrate you redux-app with router. But it doesn't limit to react-router, you can use other router and try to provide same api which react-router given now.

jadbaz commented 9 years ago

Is there an example that shows how I could use redux-router to integrate with my already configured react-router app? Thanks

chentsulin commented 9 years ago

As you can see here: https://github.com/rackt/redux-router/blob/master/examples/basic/index.js#L11, most of parts (Route, Link) are the same as what you do with react-router. redux-router just help you keep your routing state in redux's store.

jadbaz commented 9 years ago

Fair enough, But I still feel it should just integrate...

chentsulin commented 9 years ago

What does your "integrate" mean? What goal you want to achieve? If you even not use any routing state, you can leave it out of store and using just react-router is enough. But keeping routing state in store has some advantages, the one is that make mapStateToProps can use state to create selector. You can do listening history, wrapping a component, and using reducer to handle routing state change yourself, but this just create another redux-router like functionality.

gaearon commented 9 years ago

This project is an integration with React Router. If there's something in particular that is missing, please describe it in more detail.

gaearon commented 9 years ago

My question is: Is it possible to be able to achieve all the above while keeping "Router" from react-router.

No.

Take a look at <Router> source. It maintains the current state with setState() and renders <RoutingContext>.

Now take a look at <ReduxRouter> source. It connects to the current state held in Redux store and also renders <RoutingContext>.

The <RoutingContext> is shared between them. However it doesn't make sense to use <Router> directly because moving the state from inside <Router> to Redux store is the whole point of this project.

gaearon commented 9 years ago

In other words, is it possible for routing to work 100% using react-router and have redux "integration" as extra code that adds and does NOT replace while keeping control with react-router?

It is possible but it won't be “Redux way”. You can use React Router directly with Redux—but routing changes won't work with Redux DevTools, for example, and won't be dispatchable as actions.

jadbaz commented 9 years ago

Thanks Dan, Makes perfect sense!

jadbaz commented 9 years ago

Btw, what's the latest working documentation? README or basic example?

gaearon commented 9 years ago

I don't know (I'm not the primary maintainer of this project), but I assume example should be up to date.