mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-29 14:38:50 +02:00
refactor(v2): better page preloading
(#976)
* refactor: use native preloadReady for prerender on client * refactor: rename 'prerender' to 'preload' for correctness
This commit is contained in:
parent
fbdd79981d
commit
ce5610a420
4 changed files with 9 additions and 8 deletions
18
v2/lib/core/preload.js
Normal file
18
v2/lib/core/preload.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
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;
|
||||
}),
|
||||
);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue