Skip to content

Instantly share code, notes, and snippets.

@colinmeinke
Last active March 10, 2016 15:42
Show Gist options
  • Save colinmeinke/6f578e8e8bf6c0d68e3e to your computer and use it in GitHub Desktop.
Save colinmeinke/6f578e8e8bf6c0d68e3e to your computer and use it in GitHub Desktop.
import { updateId, updatePage, updateTags, getPosts, postsUpdating } from '../../actions';
import { meta } from '../../config';
const route = {
match: 'users/:id/posts',
title: state => `Blog of ${ state.user.name }`,
meta: state => [
...meta,
{ name: 'description', content: state.user.description },
],
onEnter: ( url, dispatch, getState, done ) => {
// Update redux store from url
// Would rely on batching middleware/enhancer
dispatch([
updateUser( url.id ),
updatePage( url.page ),
updateTags( url.tags ),
postsUpdating(),
]);
const state = getState();
// Do something with this new state
getPosts( state.user, state.page, state.tags ).then( action => {
dispatch( action );
done();
});
},
onExit: ( dispatch, getState, done ) => {
// Tidy up state
dispatch( updatePage());
// Or hold off navigation until ready
checkDatabaseSynced().then( done );
},
};
export default route;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment