UNPKG

alepha

Version:

Easy-to-use modern TypeScript framework for building many kind of applications.

34 lines (28 loc) 877 B
export interface WebAppRouterOptions { api?: boolean; } export const webAppRouterTs = (options: WebAppRouterOptions) => { const imports: string[] = ['import { $page } from "alepha/react/router";']; const classMembers: string[] = []; if (options.api) { imports.push('import { $client } from "alepha/server/links";'); imports.push( 'import type { HelloController } from "../api/controllers/HelloController.ts";', ); classMembers.push(" api = $client<HelloController>();"); classMembers.push(` home = $page({ path: "/", lazy: () => import("./components/Home.tsx"), loader: () => this.api.hello(), });`); } else { classMembers.push(` home = $page({ path: "/", lazy: () => import("./components/Home.tsx"), });`); } return `${imports.join("\n")} export class AppRouter { ${classMembers.join("\n\n")} }`; };