File tree 3 files changed +57
-43
lines changed
packages/sdks/snippets/remix/app
3 files changed +57
-43
lines changed Original file line number Diff line number Diff line change 1
1
import { type RouteConfig , index } from "@react-router/dev/routes" ;
2
2
3
- export default [ index ( "routes/page.tsx" ) ] satisfies RouteConfig ;
3
+ export default [ index ( "routes/builder- page.tsx" ) ] satisfies RouteConfig ;
Original file line number Diff line number Diff line change
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
+ }
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments