All files / src getRoutePreloadData.js

100% Statements 14/14
85.71% Branches 6/7
100% Functions 2/2
100% Lines 14/14
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25      3x 6x 6x 10x 10x 10x 4x 4x 4x 4x   6x     6x 4x     2x      
import { matchPath } from "react-router-dom";
import ParseEndpoint from "./ParseEndpoint";
 
const getRoutePreloadData = (routes = [], path) => {
  let data = "";
  const hasData = routes.some(route => {
    const routeInfo = { path: route.props.path, exact: route.props.exact };
    const match = matchPath(path, routeInfo);
    if (match && typeof route.props.data !== "undefined") {
      const { params } = match;
      params.url = match.url;
      data = ParseEndpoint(route.props.data, params);
      return true;
    }
    return false;
  });
 
  if (hasData) {
    return data;
  }
 
  return null;
};
export default getRoutePreloadData;