Skip to content

Latest commit

 

History

History
60 lines (41 loc) · 1.24 KB

README.md

File metadata and controls

60 lines (41 loc) · 1.24 KB

next-nginx-routes

Generate Nginx routes configuration file for Next.js static HMTL export.

This NPM package allows you to convert Next.js routes like:

{
  "page": "/[foo]",
  "regex": "^/([^/]+?)(?:/)?$",
  "routeKeys": { "foo": "foo" },
  "namedRegex": "^/(?<foo>[^/]+?)(?:/)?$"
}

... into Nginx routes like:

location ~ ^/([^/]+?)(?:/)?$ {
  try_files /[foo].html /index.html;
}

Getting started

Installation

yarn add --dev next-nginx-routes

Generate Nginx configuration file

Add next-nginx-routes to your export script:

{
  "export": "next build && next export && next-nginx-routes"
}

And run Next.js export:

yarn run export

Include Nginx configuration file

Finally include the generated configuration file next-routes.conf and the Next.js output in your Nginx site configuration file.

Requirements

More

  • See example folder for a minimal Docker example.
  • Read more about this approach in our blog post.