-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
/
Copy pathentry.client.tsx
38 lines (32 loc) · 1002 Bytes
/
entry.client.tsx
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
import * as React from "react";
import * as ReactDOM from "react-dom/client";
import {
createBrowserRouter,
matchRoutes,
RouterProvider,
} from "react-router-dom";
import { routes } from "./App";
hydrate();
async function hydrate() {
// Determine if any of the initial routes are lazy
let lazyMatches = matchRoutes(routes, window.location)?.filter(
(m) => m.route.lazy
);
// Load the lazy matches and update the routes before creating your router
// so we can hydrate the SSR-rendered content synchronously
if (lazyMatches && lazyMatches?.length > 0) {
await Promise.all(
lazyMatches.map(async (m) => {
let routeModule = await m.route.lazy!();
Object.assign(m.route, { ...routeModule, lazy: undefined });
})
);
}
let router = createBrowserRouter(routes);
ReactDOM.hydrateRoot(
document.getElementById("app")!,
<React.StrictMode>
<RouterProvider router={router} fallbackElement={null} />
</React.StrictMode>
);
}