Why would you want to do this? Because you often don't need more. It's nice to not have to think about your "router" as this big special thing.
Instead, with this approch, your app's current pathname
is just another piece of state, just like anything else.
This also means that when doing server-side rendering of a redux app, you can just do:
var app = require('your/redux/app')
var React = require('react')
// pass the URL like any other piece of data
React.renderToString(app.render({url: '/about'}))
The react-internal-nav component makes sure internal navigation clicks are captured, then we turn it into an SET_URL
action dispatch.
This example has extremely simple url matching with just a few if
statements, but this could easily be elaborated on if you needed it, using some kind of lightweight string route matcher, such as:
- https://www.npmjs.com/package/routes
- https://github.com/Matt-Esch/http-hash
- https://github.com/glassresistor/i40
- https://github.com/bevacqua/ruta3
While standalone history management tools exist, such as https://browserstate.github.io/history.js/demo/ or https://github.com/rackt/history they're concerned with proper handling the state
part of pushState
APIs. Personally, I don't want to put state there anyway and if you don't care about that part, the actual browser support for plain pushState is quite good.
Wow this is slick