mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-16 04:44:35 +00:00
13
runtime/src/app/prefetchRoutes/index.ts
Normal file
13
runtime/src/app/prefetchRoutes/index.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { components, routes } from '@sapper/internal/manifest-client';
|
||||
import { load_component } from '../app';
|
||||
|
||||
export default function prefetchRoutes(pathnames: string[]) {
|
||||
return routes
|
||||
.filter(pathnames
|
||||
? route => pathnames.some(pathname => route.pattern.test(pathname))
|
||||
: () => true
|
||||
)
|
||||
.reduce((promise: Promise<any>, route) => promise.then(() => {
|
||||
return Promise.all(route.parts.map(part => part && load_component(components[part.i])));
|
||||
}), Promise.resolve());
|
||||
}
|
||||
Reference in New Issue
Block a user