Using Free Hosting plan in Azure.
I am using Next.js features like getStaticPaths and getStaticProps to optimize my web application by pre-rendering pages. The application works perfectly locally, but when deployed to Azure using a free Static Web Apps account, specific dynamic routes are returning a 404 error.
Here is a simplified example of how I'm using getStaticPaths and getStaticProps in my app:
export async function getStaticPaths() {
return {
paths: [
{ params: { id: 'rice' } },
{ params: { id: 'okele' } },
// more paths...
{ params: { id: 'beers' } }
],
fallback: false
};
}
export async function getStaticProps({ params }) {
const menuData = await API.fetchMenu();
const categoryData = menuData.Categories.find(item => item.CategoryName.toLowerCase() === params.id);
return {
props: {
category: categoryData,
},
revalidate: 3600 // ISR
};
}
The build output on Azure indicates that all pages under /menu/[id] are generated correctly:
├ ● /menu/[id] (ISR: 3600 Seconds) (2532 ms)
├ ├ /menu/rice (592 ms)
├ ├ /menu/okele
├ └ [+5 more paths]
Despite this, navigating to domain.com/menu/rice or any other specified path under /menu/[id] results in a 404 error, while other paths like /contact or /more/faqs work without any issues.
Questions:
Why would these paths return a 404 only when deployed on Azure, despite working locally and the build logs indicating successful page generation?
Could this be related to Azure's handling of static paths or a specific configuration needed for Next.js apps on Azure Static Web Apps?
Is there a known issue or workaround that specifically addresses Next.js dynamic routing on Azure platforms?
Any insights or advice on troubleshooting this issue would be greatly appreciated.
UPDATE: I have added a staticwebapp.config.json file I didn't have one in the project before. this is what it looks like:
{
"routes": [ { "route": "/menu/*", "serve": "/menu/[id].html", "statusCode": 200 } ] }
The dynamic roots are not working when deployed to Azure, but it is still working on my local machine.




