59 | );
60 | }
61 |
62 | return (
63 | <>
64 |
65 |
66 | {!page && }
67 |
68 |
69 | {show404 ? (
70 |
71 | ) : (
72 |
81 | )}
82 | >
83 | );
84 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Next.js + Builder.io Minimal Starter
2 |
3 | This example walks you through using Builder.io with a minimal Next.js application.
4 |
5 | ## Prerequisites
6 |
7 | Before using this example, make sure you have the following:
8 |
9 | - A [Builder.io](builder.io) account. Check out the [plans](https://www.builder.io/m/pricing), which range from our free tier to custom.
10 | - [npm](https://www.npmjs.com/)
11 |
12 | A basic understanding of the following is helpful too:
13 |
14 | - The [command line](https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Understanding_client-side_tools/Command_line)
15 | - JavaScript and [React](https://reactjs.org/)
16 | - [Next.js](https://nextjs.org/)
17 | - What it means to [clone a GitHub repo](https://docs.github.com/en/repositories/creating-and-managing-repositories/cloning-a-repository)
18 |
19 | ## Overview
20 |
21 | To use this project, you need to do three things:
22 |
23 | 1. Get a copy of this repo.
24 | 1. Create a corresponding space in your account on [Builder.io](builder.io).
25 | 1. Connect the two.
26 |
27 | The next sections walk you through each step.
28 |
29 | ### Clone this project
30 |
31 | This example provides you with a ready-made application that you can copy locally and configure for use with your Builder.io account.
32 |
33 | 1. At the command line, run the following command to create a local copy of the Builder.io repo:
34 |
35 | ```shell
36 | git clone https://github.com/BuilderIO/builder.git
37 | ```
38 |
39 | 1. Change into the example application by using the `cd` command:
40 |
41 | ```shell
42 | cd builder/examples/next-js-simple
43 | ```
44 |
45 | 1. Open this directory in your favorite code editor.
46 | You'll come back here when you're ready to connect your application to your Builder space.
47 |
48 | ### Generating your Builder.io space
49 |
50 | If you've just created your Builder.io account and logged in for the first time, Builder prompts you to create a space with a new Builder site or add Builder to an existing application.
51 | For this example, click **Add Builder to an existing site or app**.
52 |
53 |
54 |
55 |
56 |
57 | **If you don't have the introductory prompt for creating a space, take the following steps. If you do have the prompt in the previous step, skip to step 4.**
58 |
59 | 1. Click on the Organization icon on the bottom left.
60 |
61 |
62 |
63 |
64 |
65 | 1. Hover over **Builder.io** and choose **+ New Space**.
66 |
67 |
68 |
69 |
70 |
71 | 1. Click **Add Builder to an existing site or app**.
72 |
73 | 1. When Builder asks you which ecommerce platform you use, select **None**.
74 |
75 | 1. Name your new space by entering "My Next.js App" and click **Create**.
76 |
77 |
78 |
79 |
80 |
81 | Now that you have a new space, the next step is connecting "My Next.js App" with your application.
82 |
83 | ### Connecting Builder.io to your application
84 |
85 | To connect your Builder.io space and your application, set the model preview URL and get your API key as follows:
86 |
87 | #### Setting the model preview URL
88 | To enable Builder to open your site in the visual editor, you will need to provide a URL that we can open which has the Builder rendering component in it.
89 |
90 | Go to the [/models](https://builder.io/models) page in Builder and choose your **page** model.
91 |
92 | Then, set the Preview URL to http://localhost:3000. Be sure to include the http://.
93 |
94 | 
95 |
96 | **Note: once you deploy your updates, you will want to update this to a public URL, such as your live site or your staging site (e.g. `https://your-site.com`), so anyone on your team can connect to your site for visual editing**
97 |
98 | #### Getting your API Key
99 |
100 | In the [Account settings](https://builder.io/account/space), copy your Public API Key. We're going to paste the API Key into your Next.js app in the next section.
101 |
102 | 
103 |
104 |
105 | In your code editor, configure `.env.production` and `.env.development` with the [Public API Key](https://builder.io/account/space) by adding a line to each file as follows, but using your Public API Key that you copied in the previous step.
106 | For example:
107 |
108 | ```shell
109 | BUILDER_PUBLIC_KEY=08837cee608a405c806a3bed69acfe2d <-- replace this with your API Key
110 | ```
111 |
112 | ## Running your application
113 |
114 | To serve your application locally, install dependencies, serve, and view your preview.
115 |
116 | 1. Install dependencies by entering the follw\owing at the command line.
117 |
118 | ```
119 | npm install
120 | ```
121 |
122 | 1. Serve your application by running the following at the command line:
123 |
124 | ```
125 | npm run dev
126 | ```
127 |
128 | 1. In your browser, go to `http://localhost:3000` to see your application.
129 |
130 | ### Experimenting
131 |
132 | Now that you have a configured Builder.io application, you can try different features, such as creating a page.
133 | Create a new page entry, assign any URL, publish and preview.
134 | For more detail and ideas on creating pages, see [Creating a landing page in Builder
135 | ](https://www.builder.io/c/docs/creating-a-landing-page).
136 |
137 | ### Deploy
138 |
139 | You can deploy anywhere you like, but for this project we recommend [Vercel](https://nextjs.org/docs/deployment).
140 | [](https://vercel.com/new/git/external?repository-url=https%3A%2F%2Fgithub.com%2Fbuilderio%2Fbuilder%2Ftree%2Fmaster%2Fexamples%2Fnext-js-simple)
141 |
142 | ## Next steps
143 |
144 | - Learn how to [use your react components in our visual editor](https://www.builder.io/c/docs/custom-react-components)
145 | - For more information on previewing your applications, see [Editing and previewing directly on your site](https://www.builder.io/c/docs/guides/preview-url).
146 | - See [Getting started with the visual editor](https://www.builder.io/c/docs/guides/page-building) for an introduction to editing your pages without having to code.
147 | - Check out [Builder best practices](https://www.builder.io/c/docs/best-practices) for guidance on how to approach site development with Builder.
148 | # next-js-example
149 |
--------------------------------------------------------------------------------