rsnext/examples/with-zones
Joe Haddad 4a12fb0a5f
Normalize example gitignores (#13768)
This removes a bunch of unnecessary `.gitignore`s and fixes some CMS examples that don't ignore `node_modules` etc.
2020-06-04 20:39:52 +00:00
..
blog Update Examples for Fast Refresh (#13068) 2020-05-18 17:44:18 -04:00
home Update Examples for Fast Refresh (#13068) 2020-05-18 17:44:18 -04:00
package.json Add package.json to with-zones example, make create-next-app work (#8453) 2019-08-20 14:45:16 -04:00
README.md Update instances of Now to Vercel where applicable (#13760) 2020-06-04 14:57:17 +00:00
vercel.json Update instances of Now to Vercel where applicable (#13760) 2020-06-04 14:57:17 +00:00

Using multiple zones

With Next.js you can use multiple apps as a single app using it's multi-zones feature. This is an example showing how to use it.

  • All pages should be unique across zones. For example, the home app should not have a pages/blog/index.js page.
  • The blog app sets assetPrefix so that generated JS bundles are within the /blog subfolder.
    • To also support the plain next dev scenario, assetPrefix is set dynamically based on the BUILDING_FOR_NOW environment variable, see vercel.json and blog/next.config.js.
    • Images and other /static assets have to be prefixed manually, e.g., <img src={`${process.env.ASSET_PREFIX}/static/image.png`} />, see blog/pages/blog/index.js.

Deploy your own

Deploy the example using Vercel:

Deploy with Vercel

How to use

Using create-next-app

Execute create-next-app with npm or Yarn to bootstrap the example:

npx create-next-app --example with-zones with-zones-app
# or
yarn create next-app --example with-zones with-zones-app

Download manually

Download the example:

curl https://codeload.github.com/vercel/next.js/tar.gz/canary | tar -xz --strip=2 next.js-canary/examples/with-zones
cd with-zones

For every app, install dependencies and run the dev server:

npm install
npm run dev
# or
yarn
yarn dev

The home app will start in the default port (http://localhost:3000), and blog will start on http://localhost:4000.

Deploy it to the cloud with Vercel (Documentation).