I have a React and Flux app and I would like to add routing to it. For example, when I call PostActions.loadPost(id), the route should automatically change to /post/:id. How do I achieve this? I am using react-router.
You can for example create a Location object as a wrapper for History API, and call Location.navigateTo(/post/${id}) inside a user action handler. E.g. handleClick(event) { event.preventDefault(); Location.navigateTo(event.target.href) }. Then you may want to add more features into it such as Location.goBack(), Location.navigateTo(url, { replace: true }) etc.
Marco Romero
Front-end Engineer
react-router is a good choice. Personally I prefer less opinionated tools so that I have the freedom to change my framework without tying my business logic to the framework.
My personal choice is to use a router like DirectorJS. Also Router5 looks like a pretty good option too.