mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-22 15:15:19 +00:00
update find_page API
This commit is contained in:
@@ -2,15 +2,14 @@ import * as glob from 'glob';
|
|||||||
import { locations } from '../config';
|
import { locations } from '../config';
|
||||||
import { create_routes } from '../core';
|
import { create_routes } from '../core';
|
||||||
|
|
||||||
export function find_page(pathname: string, files: string[] = glob.sync('**/*.*', { cwd: locations.routes(), dot: true, nodir: true })) {
|
export function find_page(pathname: string, cwd = locations.routes()) {
|
||||||
const routes = create_routes({ files });
|
const { pages } = create_routes(cwd);
|
||||||
|
|
||||||
for (let i = 0; i < routes.length; i += 1) {
|
for (let i = 0; i < pages.length; i += 1) {
|
||||||
const route = routes[i];
|
const page = pages[i];
|
||||||
|
|
||||||
if (route.pattern.test(pathname)) {
|
if (page.pattern.test(pathname)) {
|
||||||
const page = route.handlers.find(handler => handler.type === 'page');
|
return page.parts[page.parts.length - 1].component.file;
|
||||||
if (page) return page.file;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user