Files
sweet/src/types.ts
T
Marvin Hagemeister c11cf7b41a feat: expose layouts and pages on App (#3086)
This PR extracts the functionality from the `fs_routes` plugin and
exposes it onto `App`. These are the new APIs:

- `app.layout(pattern, route)`
- `app.onError(pattern, route)`
- `app.notFound(pattern, route)`
- `app.route(pattern, route)`

This also removes the need for `.use(staticFiles())`. This line can be
safely removed.

Fixes https://github.com/denoland/fresh/issues/3040
Fixes https://github.com/denoland/fresh/issues/3033
Fixes https://github.com/denoland/fresh/issues/2591
Fixes https://github.com/denoland/fresh/issues/950
Fixes https://github.com/denoland/fresh/issues/1918
2025-07-14 19:27:48 +02:00

70 lines
1.8 KiB
TypeScript

import type { RouteHandler } from "./handlers.ts";
import type { RouteComponent } from "./segments.ts";
export interface RouteConfig {
/**
* 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;
/**
* If Content-Security-Policy should be enabled for this page. If 'true', a
* locked down policy will be used that allows only the scripts and styles
* that are generated by Fresh. Additional scripts and styles can be added
* using the `useCSP` hook.
*/
csp?: boolean;
/**
* Skip already inherited layouts
* Default: `false`
*/
skipInheritedLayouts?: boolean;
/**
* Skip rendering the `routes/_app` template
* Default: `false`
*/
skipAppWrapper?: boolean;
}
export interface LayoutConfig {
/**
* Skip already inherited layouts
* Default: `false`
*/
skipInheritedLayouts?: boolean;
/**
* Skip rendering the `routes/_app` template
* Default: `false`
*/
skipAppWrapper?: boolean;
}
export interface Route<State> {
component?: RouteComponent<State>;
config?: RouteConfig;
handler?: RouteHandler<unknown, State>;
}
// TODO: Uncomment once JSR supports global types
// declare global {
// namespace preact.createElement.JSX {
// interface HTMLAttributes {
// /**
// * Alternative url to fetch partials from on `<a>` or `<form>` tags
// */
// "f-partial"?: string | SignalLike<string>;
// /**
// * Enable or disable client side navigation and partials for this
// * particular node and its children.
// */
// "f-client-nav"?: boolean | SignalLike<boolean>;
// }
// }
// }