I think that is not possible (at least not easily).
The usual way is to use the next-server (i.e. next build && next start
), which can build new pages at runtime. Otherwise your own server would need to build the HTML pages (in a next.js compatible way).
Static files and routing
I understand that you used next export
to generate static HTML pages, and you are serving them with nginx.
So all you have is a folder full of HTML files, and if you type a URL into the browsers address bar, the server has to match that URL to one of the HTML files.
A server might be pre-configured to know that e.g. the URL "/" should load "index.html", and you would see the a page, but if the server doesn't know that e.g. "/about" should load "about.html" it responds with 404
.
Compiling HTML
The "dynamic route" in Next.js is just a file like [id].js
(or in your case [id]/index.js
), which needs to be compiled into a proper e.g. 123.html
file (or directly into HTML content at runtime).
Without compiling, there is no HTML content. So some software has to create the HTML content at some point. E.g.:
- As soon as one of the pages is loaded, then the next.js scripts are loaded, and next.js can do the routing and compiling client-side (That's why the internal routing works).
- If you use the builtin next-server (i.e.
next build && next start
), the next-server has all the required routing set up.
- If you use your own server, you need to set up all the routing yourself.
getStaticPaths
The next-server (next start
) can create additional pages dynamically at runtime, so you can optionally specify only a few or none of the dynamic paths, and use the "fallback" option.
But next export
(and getStaticPaths
) only runs once at build time. Later only client-side code is executed, without filesystem access. So HTML files are only created at build time, all paths need to be specified at build time. (fallback: true
or blocking
don't work), as you said.