exportPathMap

    Examples

    exportPathMap allows you to specify a mapping of request paths to page destinations, to be used during export. Paths defined in exportPathMap will also be available when using .

    Let’s start with an example, to create a custom exportPathMap for an app with the following pages:

    • pages/about.js
    • pages/post.js

    Open next.config.js and add the following exportPathMap config:

    The pages will then be exported as HTML files, for example, /about will become /about.html.

    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:

    • dev - true when is being called in development. false when running next export. In development exportPathMap is used to define routes.
    • dir - Absolute path to the project directory
    • distDir - Absolute path to the .next/ directory (configurable with the distDir 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:

    • page: String - the page inside the directory to render
    • query: Object - the query object passed to getInitialProps when prerendering. Defaults to {}

    To switch back and add a trailing slash, open next.config.js and enable the trailingSlash config:

    will use out as the default output directory, you can customize this using the -o argument, like so: