-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.tsx
More file actions
52 lines (48 loc) · 1.18 KB
/
client.tsx
File metadata and controls
52 lines (48 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import App from "./app";
import { Suspense } from "react";
import { Route, Router } from "wouter";
import { getManifest } from "vinxi/manifest";
import { createAssets, lazyRoute } from "@vinxi/react";
import fileRoutes from "vinxi/routes";
import { pathToRegexp } from "path-to-regexp";
import { hydrateRoot } from "react-dom/client";
import "vinxi/client";
const convertPathToRegexp = (path: string) => {
let keys = [];
const pattern = pathToRegexp(path, keys, { strict: true });
return { keys, pattern };
};
const routes = fileRoutes.map((route) => ({
path: route.path,
component: lazyRoute(
route.$component,
getManifest("client"),
getManifest("ssr")
),
}));
const Assets = createAssets(
getManifest("client").handler,
getManifest("client")
);
hydrateRoot(
document,
<Router parser={convertPathToRegexp} base={(window as any).base}>
<App
assets={
<Suspense>
<Assets />
</Suspense>
}
>
<Suspense>
{routes.map((route) => (
<Route
path={route.path}
key={route.path}
component={route.component}
/>
))}
</Suspense>
</App>
</Router>
);