All files / src/utilities/loadInitialData index.js

100% Statements 8/8
100% Branches 4/4
100% Functions 1/1
100% Lines 8/8
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24            5x 4x   4x 1x     3x   3x 1x     2x        
/*
 * © Jordan Tart https://github.com/jtart
 * https://github.com/jtart/react-universal-app
 */
import { matchRoutes } from 'react-router-config';
 
const loadInitialData = async (url, routes) => {
  const matchedRoutes = matchRoutes(routes, url);
 
  if (matchedRoutes.length <= 0) {
    throw new Error(`No route was found for ${url}.`);
  }
 
  const { route, match } = matchedRoutes[0];
 
  if (!route.getInitialData) {
    return {};
  }
 
  return route.getInitialData({ match });
};
 
export default loadInitialData;