Deploying React AppsEntry 10 of 11
Deploying Under a Sub-Path
Configuring the app to run at a path like example.com/my-app/ instead of the domain root.
Notes
- Two settings must match:
- The asset base so the browser requests
/my-app/assets/.... - The router basename so routes resolve under
/my-app.
- The asset base so the browser requests
- Common for GitHub Pages and apps hosted alongside others on one domain.
What / Why / When
- What
Non-root deployment.
- Why
Without it, assets 404 and routes don't match.
- When
The app isn't served from
/.
Code compare
// vite.config.tsexport default defineConfig({ plugins: [react()], base: "/my-app/",});// App.tsxconst router = createBrowserRouter(routes, { basename: "/my-app" });ng build --base-href /my-app/The <base href> tag covers both assets and the router.
Quick reference
| Setting | React | Angular |
|---|---|---|
| Assets | base in vite.config.ts | --base-href |
| Router | createBrowserRouter(routes, { basename }) | Same <base href> |