We will define loadBranchData to use matchRoutes from react-router-config, and the routes defined in the route configuration file to look for a route matching the incoming request URL.
mern-mediastream/server/express.js:
import { matchRoutes } from 'react-router-config' import routes from './../client/routeConfig' const loadBranchData = (location) => { const branch = matchRoutes(routes, location) const promises = branch.map(({ route, match }) => { return route.loadData ? route.loadData(branch[0].match.params) : Promise.resolve(null) }) return Promise.all(promises)}
If a matching route is found, then any associated loadData method will be executed to return a Promise containing the fetched data or null if there ...