William Nemenchainitial commit
86fb32e9/11/2022, 1:13:39 AM
~app/routes.tsx
.ts
TypeScript
(application/typescript)
// 1st-party
import type { IRouteParams } from "@ethicdevs/react-monolith";
import { AppRouter, AppRouterGroup, Router } from "@ethicdevs/react-monolith";
// 3rd-party
import React from "react";
// app
/* controllers */
import * as HomeController from "./controllers/HomeController";
import * as DocumentationController from "./controllers/DocumentationController";
import * as ThemeController from "./controllers/ThemeController";

export enum DocAppRoute {
  HOME = "home",
  DOCS_HOME = "docs.home",
  DOCS_MANAGE_MEMORY_RELOAD = "docs.mgmt.memory-reload",
  DOCS_SECTION_ENTRY = "docs.section.entry",
  DOCS_SECTION_PAGE = "docs.section.page",
  THEME_SET = "theme.set",
}

export interface DocAppRoutesParams extends IRouteParams {
  [DocAppRoute.HOME]: undefined;
  [DocAppRoute.DOCS_HOME]: undefined;
  [DocAppRoute.DOCS_SECTION_ENTRY]: {
    sectionSlug: string;
  };
  [DocAppRoute.DOCS_SECTION_PAGE]: {
    sectionSlug: string;
    pageSlug: string;
  };
  [DocAppRoute.THEME_SET]: {
    themeScheme: string;
  };
}

const DocAppRouter: AppRouter = () => (
  <Router.Root>
    <></>
    <Router.Group type={AppRouterGroup.API}>
      <Router.Route
        name={DocAppRoute.HOME}
        method={"GET"}
        path={"/"}
        handler={HomeController.getHomeView}
      />
      <Router.Route
        name={DocAppRoute.DOCS_MANAGE_MEMORY_RELOAD}
        method={"GET"}
        path={"/docs/mgmt/memory-reload"}
        handler={DocumentationController.reloadDocsEndpoint}
      />
      <Router.Route
        name={DocAppRoute.DOCS_HOME}
        method={"GET"}
        path={"/docs"}
        handler={DocumentationController.getDocHomeView}
      />
      <Router.Route
        name={DocAppRoute.DOCS_SECTION_ENTRY}
        method={"GET"}
        path={"/docs/:sectionSlug"}
        handler={DocumentationController.getSectionEntrypoint}
      />
      <Router.Route
        name={DocAppRoute.DOCS_SECTION_PAGE}
        method={"GET"}
        path={"/docs/:sectionSlug/:pageSlug"}
        handler={DocumentationController.getSectionPageView}
      />
      <Router.Route
        name={DocAppRoute.THEME_SET}
        method={"GET"}
        path={"/theme/:themeScheme"}
        handler={ThemeController.getTheme}
      />
    </Router.Group>
  </Router.Root>
);

export default DocAppRouter;