A minimalistic routing approach for React.js apps

There are many cases when you don't need a fully featured routing and navigation approach, and using something similar to this will do the trick with routing, navigation and async data fetching just fine:


You may also want to check out react-routing library and react-starter-kit (disclaimer: I'm the author)

Follow me on Twitter or GitHub

Start a personal dev blog on your domain for free and grow your readership.

3.4K+ developers have started their personal blogs on Hashnode in the last one month.

Write in Markdown 路 Publish articles on custom domain 路 Gain readership on day zero 路 Automatic GitHub backup and more

Comments (3)

Jose M. Oberle's photo

This looks pretty simple and straightforward. I personally feel solutions like react-router, react-router-component etc are a little complex for beginners. Why do you think react-routing is minimalistic? What are the features that it lacks when compared to react-router?

Konstantin Tarkus's photo

The code sample above demonstrates how to implement a basic routing without using any 3rd party libraries.

And in regards to the react-routing library.. it has this concept of a routing table (basically an array) where each route is just a URL path and one or more actions (route handlers) associated with it. Inside a route handler function you're free to do whatever you want, e.g. print to the console, fire up some actions on a worker process, asynchronously fetch some data, render React component etc. (it has no dependency on React and is extremely flexible I believe ).