Integrate Landing Pages
Landing pages are the most common application of integrating page models.
Model definition
You can use the standard Page model. The Page model that Builder comes by default is named page. For this example, you'll want to make sure you have a couple of fields:
| name | type | notes |
|
| To populate the page |
|
| Optional, to populate |
You can also optionally add additional fields for other metadata.
Example Code
For landing pages in all frameworks:
- Make a catchall route.
- Check for a page at the current route. If one doesn't exist — and you're not actively previewing or editing — display a 404.
Add this as a catchall page; for example, pages/[...page].tsx (or .tsx):
Tip: If you don't have an index route, such as pages/index.tsx , use pages/[[...page.tsx]] with two sets of square brackets. The two square brackets means that Builder handles the app's home page.
The single set of square brackets, in this tutorial, assumes that you are keeping your home page.
Add this as a catchall page; for example, pages/[...page].jsx (or .tsx):
Tip: If you don't have an index route, such as pages/index.tsx , use pages/[[...page.tsx]] with two sets of square brackets. The two square brackets means that Builder handles the app's home page.
The single set of square brackets, in this tutorial, assumes that you are keeping your home page.
Create a components/builder.tsx file:
Notice that RenderBuilderContent is a component you'd make, for example:
In app/[...page]/page.tsx paste in the following:
This example uses the following path configuration in tsconfig.json:
If you prefer to use the default src path for @/*, remember to adjust your RenderBuilderContent import path.
Tip: If you don't have an index route, such as app/index.tsx , use app/[[...page.tsx]] with two sets of square brackets. The two square brackets means that Builder handles the app's home page.
The single set of square brackets, in this tutorial, assumes that you are keeping your home page.
In the app/[...slug] directory, create a file called page.tsx and paste in the following:
Tip: When deploying the React Gen 2 SDK to an edge runtime, you must use the @builder.io/sdk-react/edge import instead of @builder.io/sdk-react. This is necessary to avoid importing code that only works on NodeJS runtimes.
Want the latest and greatest of Remix with Builder? We recommend using Gen 2.
Inside the routes directory, create a file named $.tsx. and paste in the code below, making sure to replace YOUR_PUBLIC_API_KEY with your Public API Key, which you can find in the Account section of Builder or by pressing Cmd/Ctrl+k and filtering for "API".
To enable server-side rendering for the @builder.io/react package in your Vite project, you need to update your vite.config.ts file. Add the ssr property to the configuration object exported by defineConfig. Inside the ssr object, set the noExternal property to an array containing the "@builder.io/react" package name. This tells Vite not to externalize the @builder.io/react package during the SSR build process.
Make sure to place this configuration within the defineConfig function exported from your vite.config.ts file.
Tip: When deploying the React Gen 2 SDK to an edge runtime, you must use the @builder.io/sdk-react/edge import instead of @builder.io/sdk-react. This is necessary to avoid importing code that only works on NodeJS runtimes.
Inside the routes directory, create a file called ($slug)._index.tsx and paste the following code into it. Replace YOUR_API_KEY with your Public API Key, which you can find in the Account section of Builder.
Want the latest and greatest of Hydrogen with Builder? We recommend using Gen 2.
Inside the routes directory, create a file named $.tsx. and paste in the code below, making sure to replace YOUR_PUBLIC_API_KEY with your Public API Key, which you can find in the Account section of Builder or by pressing Cmd/Ctrl+k and filtering for "API".
To enable server-side rendering for the @builder.io/react package in your Vite project, you need to update your vite.config.ts file. Add the ssr property to the configuration object exported by defineConfig. Inside the ssr object, set the noExternal property to an array containing the "@builder.io/react" package name. This tells Vite not to externalize the @builder.io/react package during the SSR build process.
Make sure to place this configuration within the defineConfig function exported from your vite.config.ts file.
This example uses SvelteKit.
If your app doesn't have it, create pages/[...app].vue and paste in the following code.
If you are using an SSR framework other than Nuxt, you must import the CSS by adding the following to your entry point, before rendering Builder content:
Paste the following code into App.js.
In a new subdirectory called src/templates, create a file named page.jsx, and paste in the following:
Add the following code to the view file you want to use.
This blueprint assumes you are familiar with the tech stack and practices for integrating Builder. For more detailed instructions that use this same code, show how to install the Builder Swift SDK, and set up Appetize.io with Builder, visit Integrating Pages.
In app-routing.module.ts, import LandingPageComponent at the top with the other JavaScript imports and replace the default routes with an array with a single item:
Add the following to landing-page.component.html:
In landing-page.component.ts, add the following property:
Replace the contents of app.component.html with:
For more detailed instructions, visit Integrating Pages.