react-redux-provide-history v0.0.4
react-redux-provide-history
An alternative to react-router which provides the HTML5 History API to React components.
Installation
npm install react-redux-provide-history --saveUsage
This provides React components with the HTML5 History API via the following propTypes:
pushWindowPath- works exactly likewindow.history.pushStateexcept arguments are reversed (paththentitlethenstate)replaceWindowPath- works exactly likewindow.history.replaceStateexcept arguments are reversed (paththentitlethenstate)setDocumentTitle- setsdocument.title(why? see the followingreducers)
Your components may also be provided the following reduced props:
windowPath- essentiallywindow.location.pathnamedocumentTitle- when navigating through history, this gets updatedhistoryData- essentiallywindow.history.state, which is actually theactionthat triggered the navigation; avoid using this directly but it's there if you absolutely need it
A few notes:
Upon initializing the store,
replaceWindowPathis automatically called which can be used to properly initialize the state of any other providers who make use of this provider'sREPLACE_WINDOW_PATHaction type.When navigating through history (i.e., when the
popstateevent is triggered on thewindow), if apathis present within thewindow.history.state, theREPLACE_WINDOW_PATHaction type will be dispatched on top of thewindow.history.state(stored action) to indicate that thewindow.location.pathnamehas been changed; or if only atitleis present for some reason, theSET_DOCUMENT_TITLEaction type will be dispatched instead.If you're migrating to this from
react-routeror if you want a quick and easy way to include links in your app that work both clientside and serverside, you canimport { Link } from 'react-redux-provide-history';and use it like any otheraelement.The equivalent of
router.transitionTois to provide thepushWindowPathand/orreplaceWindowPathto your components and use wherever necessary.
Example
See bloggur and its entries provider for a good example of how to create providers that depend on the current path. (Note: react-redux-provide's shareStore utility function helps when you need providers to depend on one another.)