Skip to content

Commit b8d12fa

Browse files
committed
chore: create a separate route for prerendered page
1 parent dd0cc9e commit b8d12fa

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

src/pages/prerender.tsx

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { useContext } from "react";
2+
import { useParams, Link } from "react-router-dom";
3+
import reactLogo from "~/assets/react.svg";
4+
import Context from "~/context";
5+
6+
export default function Home() {
7+
const context = useContext(Context);
8+
9+
return (
10+
<div className="App">
11+
<div>
12+
<a href="https://vitejs.dev" target="_blank">
13+
<img src="/logo.svg" className="logo" alt="Vite logo" />
14+
</a>
15+
<a href="https://reactjs.org" target="_blank">
16+
<img src={reactLogo} className="logo react" alt="React logo" />
17+
</a>
18+
</div>
19+
<h1>Vite + React</h1>
20+
<div className="list">
21+
<p>This page is prerendered.</p>
22+
<p>
23+
Context generated on the server-side:
24+
<br /> <code>{JSON.stringify(context)}</code>
25+
</p>
26+
<p>
27+
Go back to <Link to="/">home page</Link>.
28+
</p>
29+
</div>
30+
<p className="powered-by">
31+
Template by{" "}
32+
<a
33+
href="https://www.stormkit.io/"
34+
target="_blank"
35+
rel="noopener noreferrer"
36+
>
37+
<img src="/stormkit-logo.svg" />
38+
</a>
39+
</p>
40+
</div>
41+
);
42+
}

src/prerender.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
// Check import.meta.glob provided by Vite to scan folders dynamically
55
// and build the routes to be prerendered.
66

7-
export default ["/", "/my-page", "/my-other-page"];
7+
export default ["/", "/prerender"];

src/routes.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ type RouteExtended = RouteProps & {
1313

1414
const routes: Route[] = [
1515
{ path: "/", import: () => import("~/pages") },
16+
{ path: "/prerender", import: () => import("~/pages/prerender") },
1617
{ path: "/:name", import: () => import("~/pages/ssr") },
1718
];
1819

0 commit comments

Comments
 (0)