Static export and dynamic route #32375
Replies: 7 comments 2 replies
-
Hi, Works fine on Vercel (or another deploy platform), but when exporting the app as static export, the dynamic routes are not working. Accessing a dynamic route by a Link from the root-page works, but by using the dynamic url directly, results in an error. The plan was to deploy the Nextjs-app on IFPS/Fleek. Thanks in advance. |
Beta Was this translation helpful? Give feedback.
-
Documentation says "The majority of core Next.js features needed to build a static site are supported, including. Dynamic Routes when using getStaticPaths" https://nextjs.org/docs/advanced-features/static-html-export I was not able to make it work. I get 404 error, when refresh a page with a dynamic route. I think we need more clarity, if these 2 features do work or not together. |
Beta Was this translation helpful? Give feedback.
-
Late to the party but I'm pretty sure this is an issue with how your hosting provider is configured.
This is because when you run So you need to configure a wildcard parameter with your hosting provider to match your Next.js dynamic routing. Some routing rule like |
Beta Was this translation helpful? Give feedback.
-
I struggled with this when building my static export locally and then deploying to Vercel. Thanks to the Build Output API I can now do: |
Beta Was this translation helpful? Give feedback.
-
Hello, i made a workaround using nginx rewrite rules:
but there are some limitations:
basically when nextjs build static, the dynamic route is build in a [id].html this rule replace all numbers that have a / before aka this regex: /(\d+) to /[id] and i have another nginx rule to remove the .html |
Beta Was this translation helpful? Give feedback.
-
i have the same issue, my app is deployed on Cpanel, how can i do the same .htaccess file ? |
Beta Was this translation helpful? Give feedback.
-
Cross posting from another discussion: In my Next v15 app that uses the pages router, I used this workaround to bring the router in sync with the window location. I was never able to use redirects or rewrites to solve this issue. It's a hack to work around the problem that the // _app.js
import { useEffect } from "react";
import { useRouter } from "next/router";
export default function App({ Component, pageProps }) {
const router = useRouter();
useEffect(() => {
const path = window.location.pathname;
// If we're not on the homepage but router thinks we are
if (path !== "/" && router.pathname === "/") {
// Push to the actual path
router.push(path + window.location.search + window.location.hash);
}
}, [router]);
return <Component {...pageProps} />;
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,

i have a dynamic route to edit a customer:
i'm using static export (im not using any staticpath or staticprops methods),
the page customers/10012345/edit/ :
AND i can access this url => /customers/[id]/edit/ (obviously trigger error cause its not a real id)
any idea ? i was thinking to make a rewrite rule but im not sure
thanks for helping
Beta Was this translation helpful? Give feedback.
All reactions