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

handle redux-router actions #129

Closed ZigGreen closed 8 years ago

ZigGreen commented 9 years ago

How can I handle route change actions? May I use import {ROUTER_DID_CHANGE} from 'redux-router/lib/constants' for this purpose?

apapirovski commented 9 years ago

@acdlite previously chimed in on this in #51. I think it heavily depends on what you're doing.

For example, I have a reducer for some global app state which needs to be reset on each ROUTER_DID_CHANGE, so I handle it directly. An important thing to consider here is that, unlike react-router, when you're already on a route and click on a link to it, ROUTER_DID_CHANGE will not trigger, because redux-router ignores the key property.

But on the flip side, if you're doing something like loading data or basically just trying to trigger another action, then what you need to do is listen to the store directly, use component lifecycle methods or something like the redux-rx example in the README.