Skip to content

Commit 827da34

Browse files
committed
update page template. update page filename.
1 parent c66f85c commit 827da34

File tree

3 files changed

+57
-43
lines changed

3 files changed

+57
-43
lines changed
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import { type RouteConfig, index } from "@react-router/dev/routes";
22

3-
export default [index("routes/page.tsx")] satisfies RouteConfig;
3+
export default [index("routes/builder-page.tsx")] satisfies RouteConfig;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import React from 'react';
2+
import {
3+
Content,
4+
fetchOneEntry,
5+
getBuilderSearchParams,
6+
isPreviewing,
7+
type BuilderContent,
8+
} from '@builder.io/sdk-react';
9+
10+
// Builder Public API Key set in .env file
11+
const BUILDER_API_KEY = 'ee9f13b4981e489a9a1209887695ef2b';
12+
const MODEL_NAME = 'page';
13+
14+
export default function BuilderPage() {
15+
const [notFound, setNotFound] = React.useState(false);
16+
const [content, setContent] = React.useState<BuilderContent | null>(null);
17+
18+
// get the page content from Builder
19+
React.useEffect(() => {
20+
fetchOneEntry({
21+
model: MODEL_NAME,
22+
apiKey: BUILDER_API_KEY,
23+
userAttributes: {
24+
urlPath: window.location.pathname,
25+
},
26+
options: getBuilderSearchParams(new URL(location.href).searchParams),
27+
})
28+
.then((content) => {
29+
if (content) {
30+
setContent(content);
31+
}
32+
setNotFound(!content);
33+
})
34+
.catch((err) => {
35+
console.log('Oops: ', err);
36+
});
37+
}, []);
38+
39+
// If no page is found, return
40+
// a 404 page from your code.
41+
if (notFound && !isPreviewing()) {
42+
return <div>404 Page Not Found</div>;
43+
}
44+
45+
// return the page when found
46+
return (
47+
<>
48+
{/* Render the Builder page */}
49+
<Content
50+
content={content}
51+
model={MODEL_NAME}
52+
apiKey={BUILDER_API_KEY}
53+
/>
54+
</>
55+
);
56+
}

packages/sdks/snippets/remix/app/routes/page.tsx

-42
This file was deleted.

0 commit comments

Comments
 (0)