preload errors

This commit is contained in:
Rich Harris
2018-03-04 18:26:58 -05:00
parent 7e2f5f8fb6
commit 50ecc5c130
2 changed files with 8 additions and 2 deletions

View File

@@ -271,7 +271,12 @@ export function preloadRoutes(pathnames: string[]) {
return routes
.filter(route => {
return !pathnames || pathnames.some(pathname => route.pattern.test(pathname));
if (!pathnames) return true;
return pathnames.some(pathname => {
return route.error
? route.error === pathname
: route.pattern.test(pathname)
});
})
.reduce((promise: Promise<any>, route) => {
return promise.then(route.load);

View File

@@ -13,8 +13,9 @@ export interface Component {
export type Route = {
pattern: RegExp;
params: (match: RegExpExecArray) => Record<string, string>;
load: () => Promise<{ default: ComponentConstructor }>;
error?: string;
params?: (match: RegExpExecArray) => Record<string, string>;
ignore?: boolean;
};