SPA Mode
Learn how to build Single Page Applications (SPAs) with React Router, client-side only rendering, and no server component.Overview
SPA Mode allows you to build React Router applications that run entirely in the browser, without server-side rendering. This is ideal for:- Static hosting (GitHub Pages, Netlify, Vercel)
- Applications without server requirements
- Progressive migration from client-only apps
- Electron or Tauri desktop applications
Configuring SPA Mode
Disable SSR in your React Router config:Client-Only Rendering
With SPA mode, all rendering happens in the browser:Loaders in SPA Mode
Loaders run in the browser, fetching data from APIs:Actions in SPA Mode
Actions also run client-side:Authentication
Handle authentication client-side:Environment Variables
Access client-side environment variables:Static Deployment
Build and deploy to static hosts:Loading States
Show loading indicators for client-side navigation:Error Handling
Handle API errors gracefully:Offline Support
Add service worker for offline functionality:Local Storage Cache
Cache API responses locally:Progressive Web App
Add PWA capabilities:SPA vs SSR Trade-offs
SPA Advantages:- Simpler deployment (static hosting)
- No server infrastructure needed
- Lower hosting costs
- Works offline with service workers
- Slower initial page load
- SEO challenges (requires careful meta tag management)
- No server-side data fetching benefits
- Larger initial JavaScript bundle
Best Practices
- Code splitting - Use lazy loading to reduce initial bundle size
- Cache API responses - Reduce network requests
- Handle offline - Provide graceful degradation
- Optimize assets - Compress images and minify code
- Use CDN - Serve static assets from edge locations
- Monitor performance - Track load times and bundle sizes
- Security - Never expose secrets in client code
- Meta tags - Set appropriate tags for social sharing and SEO