Deploying React Applications
Azure Static Web Apps hosts single-page apps globally with free SSL, preview environments for pull requests and optional APIs.
On this page · 5 min · Advanced
On this page
- Learning objectives
- Explanation
- Code example
- Step by step
- Real-world use
- Common mistakes
- Best practices
- Remember this
- Practice exercise
- Mini quiz
- Related topics
- My notes
- Reading time
- 5 min
- Difficulty
- Advanced
- Updated
- Oct 29, 2026
Related tutorials
Learning objectives#
- Create a Static Web App linked to GitHub
- Configure the build for Vite
- Add SPA route fallback
- Add a custom domain
Explanation#
Static Web Apps builds your app with GitHub Actions and serves the output from a global network.
For Vite, the app is at the repository root and the build output is dist.
Client-side routes such as /products/1 need a fallback so the server returns index.html instead of 404 — configured in staticwebapp.config.json.
Pull requests get their own preview URLs automatically, which makes reviews easy.
Code example: SPA fallback configuration#
{
"navigationFallback": {
"rewrite": "/index.html",
"exclude": ["/assets/*", "/*.{png,jpg,svg,ico,css,js}"]
},
"globalHeaders": {
"X-Content-Type-Options": "nosniff",
"Referrer-Policy": "strict-origin-when-cross-origin"
}
}
Deep links like https://<app>.azurestaticapps.net/products/1 load correctly, while real files under /assets are served directly.
This example is illustrative. Copy or download it and run it in your own environment; the expected output is shown above.
Step-by-step explanation#
- Putting the file in public/ copies it into dist on build.
- navigationFallback rewrites unknown routes to index.html so React Router can handle them.
- Excluded patterns are served as real files.
- Global headers add basic security headers to every response.
Real-world use case#
A React portfolio or dashboard deployed on every push to main, with PR previews for review — on a generous free tier.
Common mistakes#
Refreshing /dashboard returns 404 because the file does not exist. Add the fallback.
Anything prefixed VITE_ is bundled into public JavaScript. Keep secrets on the server.
Best practices#
- Set output location to dist for Vite
- Configure navigationFallback for SPAs
- Use PR preview environments
- Keep API keys on the server (e.g. Azure Functions API)
Remember this#
Vite → app location /, output dist.
SPA needs fallback to index.html.
VITE_ variables are public.
Practice exercise#
Your task: Which values would you set in the Static Web Apps workflow for a Vite app in the repo root?
Show solution
app_location: "/"
output_location: "dist"
Mini quiz#
Why does a SPA need a navigation fallback?
Want more? Practise all Microsoft Azure MCQs · Microsoft Azure interview questions
My notes#
Saved in this browser.