By saikouah
First of all thank you for the release of this product!
I have an app nextjs that I export in static and so I have a folder containing all my pages with the .html extension.
When the site is loaded and I click on a link in the page (next/link) the redirection is done. However, when I refresh the page, I get a 404 because he can’t find the page and expects to get .html at the end of the url.
Is it possible to redirect the url example.com/a to example.com/a.html automatically?
Kind regards
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
App Platform doesn’t handle this type of routing. It will only do top-level routing. It sounds like you’ll want to use an internal router like next/router to handle routing inside of your app.
next/link works in the same way as next/router. You only have more freedom with the last one.
The problem does not come from there but from the resolution of the routes directly.
The only solution for the moment is to deploy a webserver and run the next start command.
But in doing so I lose the capability of the cdn? Or create another component that contains the deployment of the output of the next build (_next dir and other files) and have a webserver component that will run next start.
👋🏼 Like @crashoverride said this currently isn’t supported by App Platform however you can configure Next.js to generate the static HTML files in a way that allows you access the routes as /page instead of /page.html.
To enable this option, add the following to next.config.js:
module.exports = {
trailingSlash: true,
}
This will generate the /page as /page/index.html instead of /page.html.
I’ve tested this and you can see an example in this repo: https://github.com/kamaln7/nextjs-static-index.html-example
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.