UNPKG

react-router

Version:

A complete routing library for React

36 lines (29 loc) 1.04 kB
import { mapAsync } from './AsyncUtils'; import makeStateWithLocation from './makeStateWithLocation'; function getComponentsForRoute(nextState, route, callback) { if (route.component || route.components) { callback(null, route.component || route.components); return; } var getComponent = route.getComponent || route.getComponents; if (!getComponent) { callback(); return; } var location = nextState.location; var nextStateWithLocation = makeStateWithLocation(nextState, location); getComponent.call(route, nextStateWithLocation, callback); } /** * Asynchronously fetches all components needed for the given router * state and calls callback(error, components) when finished. * * Note: This operation may finish synchronously if no routes have an * asynchronous getComponents method. */ function getComponents(nextState, callback) { mapAsync(nextState.routes, function (route, index, callback) { getComponentsForRoute(nextState, route, callback); }, callback); } export default getComponents;