🐛 Fix ts-router example (fix #4)
This commit is contained in:
@@ -2,7 +2,7 @@ import { Component } from "solid-js";
|
||||
import { Link, Route, useRouter } from "solid-app-router";
|
||||
|
||||
const App: Component = () => {
|
||||
const router = useRouter();
|
||||
const [router] = useRouter();
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import { DataFn } from "solid-app-router";
|
||||
import { mergeProps } from "solid-js";
|
||||
|
||||
const HomeData: DataFn = (props) => {
|
||||
return mergeProps(props, {
|
||||
const AboutData: DataFn = () => {
|
||||
return {
|
||||
name: "about",
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export default HomeData;
|
||||
export default AboutData;
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { Suspense } from "solid-js";
|
||||
|
||||
export default function About(props) {
|
||||
return (
|
||||
<section class="bg-pink-100 text-gray-700 p-8">
|
||||
|
||||
+12
-19
@@ -1,26 +1,19 @@
|
||||
import { lazy } from "solid-js";
|
||||
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();
|
||||
const Comp = pages[path] as () => Promise<{ default: Component<any> }>;
|
||||
|
||||
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;
|
||||
});
|
||||
import Home from "./pages/home";
|
||||
import AboutData from "./pages/about.data";
|
||||
|
||||
export const routes: RouteDefinition[] = [
|
||||
...autoRoutes,
|
||||
{
|
||||
path: "/",
|
||||
component: Home,
|
||||
},
|
||||
{
|
||||
path: "/about",
|
||||
component: lazy(() => import("./pages/about")),
|
||||
data: AboutData,
|
||||
},
|
||||
{
|
||||
path: "**",
|
||||
component: lazy(() => import("./errors/404")),
|
||||
|
||||
Reference in New Issue
Block a user