Search code examples
reactjswebpackreact-routercode-splitting

DRY react-router's getComponent functions


Routing with react-router, redux and redux-saga entails a lot of repeated code, just have a look here. 21 lines for a single route. In my app I have dozens of routes, so it is very important to DRY it out somehow. Otherwise this file routes.js will be a mess with 1000+ lines.

Any ideas?


Solution

  • Finally I came to this. It works fine and helps to make one route declaration just 4 lines for simple routes and 8 for those using sagas and childRoutes.