I'm using Nextjs for a front-end application and dotnet core 3.1 for the Web API. There are some pages that are static and other that are dynamic I followed the official documentation to achieve this. On development mode (local machine) everything works fine. Both static and dynamic routes are working properly and fetching data from the dontnet core Web API.
However, when publishing the Nextjs app following this steps:
- yarn build
- yarn export
- An out folder is generated at the root of the project
- The content of that folder is uploaded to the server
After, the deployed files are uploaded and when loging to the app, it redirects to the main page (until here is working OK), but as soon as I click on the reload page botton (Chrome) I am gettint the 404 error.
Looking at the console in the developer tools I got this:
I found this Stackoverflow link with same issue but there the answer is to use Express for server routing. In my case I am using dotnet core Web API for server requests. So, not sure how to do that.
Is there a way to fix this from the client side? Might be a configuration is missing?
The only thing I noticed while doing the export was a message saying: No "exportPathMap" found. Not sure if that would the the reason.
"The content of that folder is uploaded to the server"
it is a static web hosting (S3, blob storage, etc) ? 2. The pageaccount.html
is inside the exported files? If so, if you openhttp://yourpath/account.html
it opens the page? 3."After, the deployed files are uploaded and when loging to the app, it redirects to the main page (until here is working OK)"
I think is because you're doing full client side navigation (with push history from html) but once you reload the page the path/account/
is not registered. – Pierfrancesco.html
in file extension for all files generated by export excepts forindex.html
. Then setContentType
totext/html
for all the files you've removed the extension. – Pierfrancesco