I deployed my static website (React app) to Azure App Service with routes.json to enable HTML5 routing fallback. My routes json is located in /public and is available under URL https://mywebsite.azurewebsites.net/routes.json.
{
"routes": [
{
"route": "/*",
"serve": "/index.html",
"statusCode": 200
}
]
}
The redirect doesn't work. What am I doing wrong?
Newest
I think you confuse the two services
Web AppandStatic Web App. Theroutes.jsonfile only takes effect in Static Web App.According to the React documentation, execute the following command to create the my-app project.
npx create-react-app my-appcd my-appnpm run startThen create
index2.htmlin the public folder.Create a new repository in github with the name
reacttest.In the my-app directory, open cmd and execute the following command to upload the code to github.
git initgit add.git commit -m'init'git remote add origin https://github.com/yourname/reacttest.gitgit push -u origin masterFollow the official documentation to create
Azure Static Web Apps Preview. Check the release status inActionin github. You can see the default page after publishing.At this time, directly add the
routes.jsonfile in the public folder in github. Continue to check the publishing status in Action. After the publishing is completed, you can see that the route is in effect.When we visit the default homepage, we can see the content of
index2.html.If want see
index.html, we can add/index.htmlin url.