Edit: I managed to get dynamic routes to work in Azure Static web app. You need to have two things in your project.
- Remember to add the function of generateStaticParams in the page.tsx of your dynamic route. It is a nextjs13 app router function to create the static bundle. More info here in Static Export for App Router documentation and in generateStaticParams documentation.
- Add staticwebapp.config.json file in the project root. More info in the Azure SWA documentation. (Really only you need the next code):
"navigationFallback": {
"rewrite": "index.html",
"exclude": ["*.{css,scss,js,png,gif,ico,jpg,svg}"]
},
If you have pipeline:
- Upload this file in the section pipeline/library
- Update your pipeline to includes the artifact (Replace {BUILD} by your build name folder)
// ... first steps of your pipeline
- task: DownloadSecureFile@1
name: staticwebapp
inputs:
secureFile: 'staticwebapp.config.json'
displayName: 'Obtain the staticwebapp file from the library'
- task: Bash@3
inputs:
targetType: 'inline'
script: 'cp $(staticwebapp.secureFilePath) {BUILD}/'
workingDirectory: '$(System.DefaultWorkingDirectory)'
displayName: 'Copy staticwebapp.config.json file to app location'
// ... Here you code of connect your Azure SWA with your repo.
- Authorize the security file one time when you run your pipeline (you will see the option after run the pipeline with an alert message).
I hope to help somebody with this.