Skip to content

Instantly share code, notes, and snippets.

@cellog
Created March 21, 2017 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cellog/273563db116cdea9fa4efd502c1b370e to your computer and use it in GitHub Desktop.
Save cellog/273563db116cdea9fa4efd502c1b370e to your computer and use it in GitHub Desktop.
More in-depth example
import Routes from 'react-redux-saga-router/Routes'
import Route from 'react-redux-saga-router/Route'
import * as actions from './actions'
const stateFromParams = (params) =>
(params.id === 'new') ? { id: true } : { id: params.id ? params.id : false }
function paramsFromState(state) {
if (state.records.selectedRecord) {
return {
id: state.records.selectedRecord === true ? 'new' : state.records.selectedRecord
}
}
return {
id: undefined
}
}
const updateState = {
id: id => actions.selectRecord(id)
}
export default () => (
<Routes>
<Route name="records" path="/records(/:id)"
stateFromParams={stateFromParams}
paramsFromState={paramsFromState}
updateState={updateState}
/>
</Routes>
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment