React-router @@router/LOCATION_CHANGE available in subcomponents Updaters #40
Description
Use componentWillReceiveProps method
see: example below
--- ORIGINAL QUESTION
One of the issues during react-router integration is detecting route changes which doesn't trigger component unmounting. Example:
I've got routes: orders/1
, orders/2
, etc. (defined with orders/:id
in router)
All of them uses same OrderForm subcomponent so if I switch between them the only action triggered is @@router/LOCATION_CHANGE
(triggered by react-router
). Unfortunately OrderForm
component is nested inside OrderPage
component so it doesn't receive that action (because it is not prefixed properly).
My current solution for that is to propagate @@router/LOCATION_CHANGE
action through all of the updaters with code like the following:
// this is Updater code
.case('@@router/LOCATION_CHANGE', (model, action) => (
{
...model,
login: loginUpdater(model.loginPage, action),
lostPassword: lostPasswordUpdater(model.lostPasswordPage, action),
home: homeUpdater(model.homePage, action),
order: orderUpdater(model.orderPage, action),
}
)).toReducer();
Good part is that it works and I can handle @@router/LOCATION_CHANGE
in subcomponents but I doesn't look nice and requires such code for every level of nesting.
Does anyone has any better solution?
Setting @@
as global prefix would be nice, so all actions prefixed with @@
will be available for all elm components.
Even better option would be possibility to define (maybe in array) all "global" action prefixes. It will solve future possible problems with other react libraries (e.g. redux-form
prefix for redux-form
related actions).