mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-05 13:17:23 +02:00
* refactor: use native preloadReady for prerender on client * refactor: rename 'prerender' to 'preload' for correctness
18 lines
563 B
JavaScript
18 lines
563 B
JavaScript
import {matchRoutes} from 'react-router-config';
|
|
|
|
/**
|
|
* This helps us to make sure all the async component for that particular route
|
|
* is loaded before rendering. This is to avoid loading screens on first page load
|
|
*/
|
|
export default function preload(routeConfig, providedLocation) {
|
|
const matches = matchRoutes(routeConfig, providedLocation);
|
|
return Promise.all(
|
|
matches.map(match => {
|
|
const {component} = match.route;
|
|
if (component && component.preload) {
|
|
return component.preload();
|
|
}
|
|
return undefined;
|
|
}),
|
|
);
|
|
}
|