feat: support overriding page routes (#57)

This commit is contained in:
Luca Casonato
2021-09-25 11:27:16 +02:00
committed by GitHub
parent 70224610f9
commit a25ec7109c
6 changed files with 48 additions and 10 deletions
+8
View File
@@ -32,4 +32,12 @@ export interface PageConfig {
* the client.
*/
runtimeJS?: boolean;
/**
* A route override for the page. This is useful for pages where the route
* can not be expressed through the filesystem routing capabilities.
*
* The route override must be a path-to-regexp compatible route matcher.
*/
routeOverride?: string;
}
+5 -2
View File
@@ -41,10 +41,13 @@ export class ServerContext {
}
const path = url.substring(baseUrl.length).substring("pages".length);
const baseRoute = path.substring(1, path.length - extname(path).length);
const route = pathToRoute(baseRoute);
const name = baseRoute.replace("/", "-");
if (!path.startsWith("/_")) {
const { default: component, config } = (module as PageModule);
let route = pathToRoute(baseRoute);
if (config?.routeOverride) {
route = String(config.routeOverride);
}
let { handler } = (module as PageModule);
handler ??= {};
if (
@@ -59,7 +62,7 @@ export class ServerContext {
name,
component,
handler,
runtimeJS: config?.runtimeJS ?? false,
runtimeJS: Boolean(config?.runtimeJS ?? false),
};
pages.push(page);
} else if (