Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit 29599d4

Browse files
committed
Clean up
1 parent e44e080 commit 29599d4

File tree

5 files changed

+13
-11
lines changed

5 files changed

+13
-11
lines changed

framework/core/route.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@ export type Route = readonly [
2323
meta: RouteMeta,
2424
];
2525

26-
export type Routes = {
26+
export type RouteRecord = {
27+
routes: Route[];
2728
_404?: Route;
2829
_app?: Route;
2930
_error?: Route;
30-
routes: Route[];
3131
};
3232

3333
/** match routes against the given url */
3434
export function matchRoutes(
3535
url: URL,
36-
{ routes, _app, _404 }: Routes,
36+
{ routes, _app, _404 }: RouteRecord,
3737
): [ret: URLPatternResult, route: RouteMeta][] {
3838
let { pathname } = url;
3939
if (pathname !== "/") {

framework/react/context.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { createContext } from "react";
44
export type RouterContextProps = {
55
url: URL;
66
params: Record<string, string>;
7+
e404?: boolean;
78
ssrHeadCollection?: string[];
89
createPortal?: (children: ReactNode, container: Element, key?: null | string) => ReactPortal;
910
};

framework/react/router.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { createElement, StrictMode, useContext, useEffect, useMemo, useState } f
33
import events from "../core/events.ts";
44
import FetchError from "../core/fetch_error.ts";
55
import { redirect } from "../core/redirect.ts";
6-
import type { Route, RouteMeta, RouteModule, Routes } from "../core/route.ts";
6+
import type { Route, RouteMeta, RouteModule, RouteRecord } from "../core/route.ts";
77
import { matchRoutes } from "../core/route.ts";
88
import { URLPatternCompat } from "../core/url_pattern.ts";
99
import { ForwardPropsContext, RouterContext, type RouterContextProps } from "./context.ts";
@@ -217,6 +217,7 @@ export const Router: FC<RouterProps> = ({ ssrContext, suspense, createPortal })
217217
value: {
218218
url,
219219
params,
220+
e404: modules[modules.length - 1].url.pathname === "/_404" ? true : undefined,
220221
ssrHeadCollection: ssrContext?.headCollection,
221222
createPortal,
222223
},
@@ -291,7 +292,7 @@ export const useForwardProps = <T = Record<string, unknown>>(): T => {
291292
return props as T;
292293
};
293294

294-
function loadRoutesFromTag(): Routes {
295+
function loadRoutesFromTag(): RouteRecord {
295296
const el = window.document?.getElementById("routes-manifest");
296297
if (el) {
297298
try {

server/renderer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import FetchError from "../framework/core/fetch_error.ts";
2-
import type { RouteModule, Routes } from "../framework/core/route.ts";
2+
import type { RouteModule, RouteRecord } from "../framework/core/route.ts";
33
import { matchRoutes } from "../framework/core/route.ts";
44
import log from "../lib/log.ts";
55
import util from "../lib/util.ts";
@@ -41,7 +41,7 @@ export type SSRResult = {
4141
};
4242

4343
export type RenderOptions = {
44-
routes: Routes;
44+
routes: RouteRecord;
4545
indexHtml: Uint8Array;
4646
customHTMLRewriter: Map<string, HTMLRewriterHandlers>;
4747
isDev: boolean;
@@ -336,7 +336,7 @@ export default {
336336
async function initSSR(
337337
req: Request,
338338
ctx: Record<string, unknown>,
339-
routes: Routes,
339+
routes: RouteRecord,
340340
suspense: boolean,
341341
onError?: (error: unknown, cause: { by: "ssr"; url: string }) => Response | void,
342342
): Promise<

server/routing.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { extname, globToRegExp, join } from "https://deno.land/[email protected]/path/mod.ts";
2-
import type { Route, Routes } from "../framework/core/route.ts";
2+
import type { Route, RouteRecord } from "../framework/core/route.ts";
33
import { URLPatternCompat, type URLPatternInput } from "../framework/core/url_pattern.ts";
44
import { getFiles } from "../lib/fs.ts";
55
import log from "../lib/log.ts";
@@ -33,7 +33,7 @@ export async function importRouteModule(filename: string) {
3333

3434
/* check if the filename is a route */
3535
export function isRouteFile(filename: string): boolean {
36-
const currentRoutes: Routes | undefined = Reflect.get(globalThis, "__ALEPH_ROUTES");
36+
const currentRoutes: RouteRecord | undefined = Reflect.get(globalThis, "__ALEPH_ROUTES");
3737
const index = currentRoutes?.routes.findIndex(([_, meta]) => meta.filename === filename);
3838
if (index !== undefined && index !== -1) {
3939
return true;
@@ -54,7 +54,7 @@ type RouteRegExp = {
5454
};
5555

5656
/** initialize routes from routes config */
57-
export async function initRoutes(config: string | RoutesConfig | RouteRegExp, cwd = Deno.cwd()): Promise<Routes> {
57+
export async function initRoutes(config: string | RoutesConfig | RouteRegExp, cwd = Deno.cwd()): Promise<RouteRecord> {
5858
return await globalIt("__ALEPH_ROUTES", async () => {
5959
const reg = isRouteRegExp(config) ? config : toRouteRegExp(config);
6060
const files = await getFiles(join(cwd, reg.prefix));

0 commit comments

Comments
 (0)