类型定义

@feoe/fs-router 的 TypeScript 类型定义。

核心类型

1export interface RouteConfig {
2  path: string
3  element: React.ComponentType
4  children?: RouteConfig[]
5  loader?: LoaderFunction
6  action?: ActionFunction
7}
8
9export interface LoaderFunction {
10  (args: LoaderFunctionArgs): Promise<any> | any
11}
12
13export interface ActionFunction {
14  (args: ActionFunctionArgs): Promise<any> | any
15}

插件选项类型

1export interface PluginConfig {
2  /** 路由文件目录 */
3  routesDirectory: string
4  /** 生成的路由文件路径 */
5  generatedRoutesPath: string
6  /** 路由文件扩展名 */
7  routeExtensions?: string[]
8  /** 是否启用路由生成 */
9  enableGeneration?: boolean
10  /** 路径别名配置 */
11  alias?: {
12    name: string
13    basename: string
14  }
15  /** 是否启用代码分割 */
16  splitting?: boolean
17  /** 是否启用默认错误边界 */
18  defaultErrorBoundary?: boolean
19  /** 类型生成选项 */
20  typeGenerateOptions?: TypeGenerateOptions
21}
22
23export interface TypeGenerateOptions {
24  /** 类型文件输出路径 */
25  routesTypeFile: string
26  /** 是否生成路由参数类型 */
27  generateRouteParams?: boolean
28  /** 是否生成 Loader 类型 */
29  generateLoaderTypes?: boolean
30  /** 路由目录配置 */
31  routesDirectories?: RouteDirectory[]
32}
33
34export interface RouteDirectory {
35  /** 路由前缀 */
36  prefix?: string
37  /** 路由目录路径 */
38  path: string
39}