Dynamic Routes For Pages
planned
Binary Logic
It'd be nice to define dynamic routes for pages, outside of defining an entire plugin. For example:
/release-notes/:version
Where a /src/pages/release-notes.js file could handle all versions passed. It could use the React Router as shown here:
Sébastien Lorber
planned
Endilie Yacop Sucipto
It's possible for Server Side Rendering and Client Side Rendering but not for Static Site Rendering.
Why so ?
Because static site rendering requires us to build everything in build time, and basically there's Infinity combination of
:version
. If i were to request "www.example.com/release-notes/1.0.0". In static site case, this will request "release-notes/1.0.0.html". This is possible in Server Side Rendering because we only build HTML on demand. For CSR, we always serve index.html.
Yangshun Tay
Endilie Yacop Sucipto: That's a tradeoff that has to be made. We kinda already do that with the feedback page and its routes right? Next.js also supports such a dynamic routing approach (https://nextjs.org/docs#dynamic-routing).
We can consider it.
Endilie Yacop Sucipto
Yangshun Tay: Hmm.. Feedback page was a 404 hack and might not work in other webserver (try other webserver that doesnt redirect to 404.html, for example if you use google static storage or deploy your own static hosting). Its also not a good SEO because we never really render feedback/xxxx.html
When you go to feedback/xxx (first page load), it actually go to 404.html. Its just that I swizzled the NotFoundPage to render the Feedback component if its location is feedback/xxxx
The thing is, nextjs can do that because its a “Server Side Rendering”. It never build html unless requested. So when user request /feedback/xxxx, the Nodejs (expressjs) backend will then render the HTML and send it to user
On the other hand, we are s static site generator, and everything is just bunch of HTML.
Endilie Yacop Sucipto
Since the exported site is completely static. The browser just goes to the URL you tell it to (for example: /feedback/23) and it will request feedback/23.html
The only way to do this is with a backend (usually nginx/haproxy) that routes requests to correct pages. Some providers (like AWS's s3 buckets) will allow you to make these maps. Or in nextjs case, they use a node (expressjs) server
Endilie Yacop Sucipto
Taken from https://nextjs.org/docs#limitation
You won't be able to render HTML dynamically when static exporting, as we pre-build the HTML files. If you want to do dynamic rendering use next start or the custom server API