You can get the locationvariable parameters from the onEntercallback of your route, and then send the action to save.
See the example above:
import React from 'react';
import ReactDOM from 'react-dom';
import { createStore } from 'redux';
import App from './App';
import { Route, Router, browserHistory } from 'react-router';
const store = createStore(rootReducer);
const routes = (
<Route
path="/location/:location"
component={App}
onEnter={handleEnter}
/>
);
function rootReducer(state = {
location: {},
}, action) {
switch (action.type) {
case 'ADD_TO_LOCATION':
return {
...state,
location: action.location,
};
default:
return state;
}
return state;
}
function handleEnter(nextState) {
// Map location data here.
// Next, we are dispatching mapped location to store.
store.dispatch({
type: 'ADD_TO_LOCATION',
location: nextState.params.location,
});
}
ReactDOM.render(<Router routes={routes} history={browserHistory} />, document.getElementById('root'));
source
share