RouteParams
ページと route.ts のファイルの形のパスごとに、そのルートのパラメータの名前から値への対応を表す。declare module "sobria/router" で拡張できる。
interface RouteParams {}RouteHandlerPaths
route.ts のファイルの形のパスごとに、そのルートの Hono のパスを表す。declare module "sobria/router" で拡張できる。
interface RouteHandlerPaths {}PageProps
Route のページが受け取る props を表す。url はリクエストの URL である。
interface PageProps<Route extends PageRoute> {
readonly params: RouteParams[Route];
readonly url: URL;
}
type PageRoute = Exclude<keyof RouteParams, keyof RouteHandlerPaths>;LayoutProps
レイアウトが受け取る props を表す。url はリクエストの URL である。
interface LayoutProps {
readonly params: Readonly<Record<string, string>>;
readonly url: URL;
readonly children: ServerNode;
}NotFoundProps
not-found のページが受け取る props を表す。url はリクエストの URL である。
interface NotFoundProps {
readonly params: Readonly<Record<string, string>>;
readonly url: URL;
}ErrorProps
error のページが受け取る props を表す。error は投げられた値である。フォームの送信先のサーバー関数が失敗したときは、url は送信元のページの URL である。
interface ErrorProps extends NotFoundProps {
readonly error: unknown;
}Prerender
Route のパラメータが無ければ true を表す。パラメータのあるページなら、そのパラメータの配列を返す関数を表す。パラメータのある route.ts のルートでは never を表す。
type Prerender<Route extends keyof RouteParams> = keyof RouteParams[Route] extends never
? true
: Route extends keyof RouteHandlerPaths
? never
: () => readonly Params<Route>[] | Promise<readonly Params<Route>[]>;
type Params<Route extends keyof RouteParams> = {
readonly [Name in keyof RouteParams[Route]]: string | number;
};href
ページか route.ts のファイルの形のパス route とパラメータから、アプリを配置するパス(Vite の base)で始まる URL を返す。パラメータの値は URL エンコードし、キャッチオールの値は / を区切りとして残す。クエリが空でなければ、? に続けて付ける。
function href<Route extends keyof RouteParams>(
route: Route,
...[params, query]: HrefArgs<Route>
): string;
type HrefArgs<Route extends keyof RouteParams> =
true extends IsUnion<Route>
? never
: keyof RouteParams[Route] extends never
? [params?: undefined, query?: Query]
: [params: Params<Route>, query?: Query];
type IsUnion<T, U = T> = T extends unknown ? ([U] extends [T] ? false : true) : never;
type Query = Readonly<Record<string, string | number>> | URLSearchParams;
type Params<Route extends keyof RouteParams> = {
readonly [Name in keyof RouteParams[Route]]: string | number;
};