exportPathMap
Examples
exportPathMap
allows you to specify a mapping of request paths to page destinations, to be used during export.
Let’s start with an example, to create a custom exportPathMap
for an app with the following pages:
pages/index.js
pages/about.js
pages/post.js
Open next.config.js
and add the following exportPathMap
config:
exportPathMap
is an async
function that receives 2 arguments: the first one is defaultPathMap
, which is the default map used by Next.js. The second argument is an object with:
dir
- Absolute path to the project directoryoutDir
- Absolute path to theout/
directory (). Whendev
istrue
the value ofoutDir
will benull
.distDir
- Absolute path to the.next/
directory (configurable with thedistDir
config)buildId
- The generated build id
The returned object is a map of pages where the key
is the pathname
and the value
is an object that accepts the following fields:
query
:Object
- thequery
object passed togetInitialProps
when prerendering. Defaults to{}
The exported
pathname
can also be a filename (for example,/readme.md
), but you may need to set theContent-Type
header totext/html
when serving its content if it is different than.html
.
It is possible to configure Next.js to export pages as index.html
files and require trailing slashes, /about
becomes /about/index.html
and is routable via /about/
. This was the default behavior prior to Next.js 9.
will use as the default output directory, you can customize this using the -o
argument, like so:
[
Introduction to next.config.js
Learn more about the configuration file used by Next.js.]($0b4bd5a3a6817758.md)
[