Adding new template with automatique routing

This commit is contained in:
Alexandre
2021-02-22 13:40:00 +01:00
parent 97a4535c81
commit 9648bb5230
14 changed files with 961 additions and 0 deletions
+24
View File
@@ -0,0 +1,24 @@
import { RouteDefinition } from "solid-app-router";
import { lazy, Component } from "solid-js";
const pages = import.meta.glob("./pages/**/*.tsx");
const autoRoutes = Object.keys(pages).map((path) => {
const name = path.match(/\.\/pages(.*)\.[tj]sx$/)[1].toLowerCase();
const Comp = pages[path] as () => Promise<{ default: Component<any> }>;
const routePath = ["/home", "/index"].includes(name) ? "/" : name;
return {
path: routePath,
component: lazy(Comp),
} as RouteDefinition;
});
export const routes: RouteDefinition[] = [
...autoRoutes,
{
path: "**",
component: lazy(() => import("./errors/404")),
},
];