mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-15 04:14:46 +00:00
move app logic into templates (#444)
This commit is contained in:
14
templates/src/client/prefetchRoutes/index.ts
Normal file
14
templates/src/client/prefetchRoutes/index.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { manifest, load_component } from "../app";
|
||||
|
||||
export default function prefetchRoutes(pathnames: string[]) {
|
||||
if (!manifest) throw new Error(`You must call init() first`);
|
||||
|
||||
return manifest.pages
|
||||
.filter(route => {
|
||||
if (!pathnames) return true;
|
||||
return pathnames.some(pathname => route.pattern.test(pathname));
|
||||
})
|
||||
.reduce((promise: Promise<any>, route) => promise.then(() => {
|
||||
return Promise.all(route.parts.map(part => part && load_component(part.component)));
|
||||
}), Promise.resolve());
|
||||
}
|
||||
Reference in New Issue
Block a user