@vaadin/hilla-file-router
Version:
Hilla file-based router
44 lines (43 loc) • 1.27 kB
TypeScript
import type { Logger } from "vite";
import type { ViewConfig } from "../types.js";
export type RouteMeta = Readonly<{
path: string
file?: URL
layout?: URL
flowLayout?: boolean
config?: ViewConfig
children?: readonly RouteMeta[]
}>;
/**
* Routes collector options.
*/
export type CollectRoutesOptions = Readonly<{
/**
* The list of extensions for files that will be collected as routes.
*/
extensions: readonly string[]
/**
* The parent directory of the current directory. This is a
* nested parameter used inside the function only.
*/
parent?: URL
/**
* The Vite logger instance.
*/
logger: Logger
}>;
/**
* Collect route metadata from the file system and build a route tree.
*
* It accepts files that start with `@` as special files.
* - `@layout` contains a component that wraps the child components.
* - `@index` contains a component that will be used as the index page of the directory.
*
* It accepts files that start with `_` as private files. They will be ignored.
*
* @param dir - The directory to collect routes from.
* @param options - The options object.
*
* @returns The route metadata array.
*/
export default function collectRoutesFromFS(dir: URL, { extensions, logger, parent }: CollectRoutesOptions): Promise<readonly RouteMeta[]>;