✨ Handle data endpoint
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
import { DataFn } from "solid-app-router";
|
||||
import { mergeProps } from "solid-js";
|
||||
|
||||
const HomeData: DataFn = (props) => {
|
||||
return mergeProps(props, {
|
||||
name: "about",
|
||||
});
|
||||
};
|
||||
|
||||
export default HomeData;
|
||||
@@ -2,6 +2,7 @@ import { RouteDefinition } from "solid-app-router";
|
||||
import { lazy, Component } from "solid-js";
|
||||
|
||||
const pages = import.meta.glob("./pages/**/*.tsx");
|
||||
const pagesData = import.meta.globEager("./pages/**/*.data.ts");
|
||||
|
||||
const autoRoutes = Object.keys(pages).map((path) => {
|
||||
const name = path.match(/\.\/pages(.*)\.[tj]sx$/)[1].toLowerCase();
|
||||
@@ -9,9 +10,12 @@ const autoRoutes = Object.keys(pages).map((path) => {
|
||||
|
||||
const routePath = ["/home", "/index"].includes(name) ? "/" : name;
|
||||
|
||||
const data = pagesData[path.replace("tsx", "data.ts")] || {};
|
||||
|
||||
return {
|
||||
path: routePath,
|
||||
component: lazy(Comp),
|
||||
data: data.default,
|
||||
} as RouteDefinition;
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user