Help centerProjects, domains & DNS
SPA apps (React, Vue, Flutter…)
How to run single-page apps (React, Vue, Angular, Flutter Web, Lovable, Bolt…) on the customer's domain: navigation mode, initial route, HTML cache and gotchas.
Single-page apps (SPAs) load one HTML page and switch screens in the browser without reloading: React, Vue, Angular, Svelte, Flutter Web and the apps built by Lovable, Bolt and similar tools. Most of them work on the customer's domain without any changes. This article covers the options for when you use routes with SPAs, and how to make the app faster.
Where to configure it
The options live in the Single-page app (SPA) card on the project's Overview tab, and apply to every domain in the project:
- Open the project and stay on the Overview tab;
- In the Single-page app (SPA) card, pick the Navigation mode;
- If needed, turn on Send initial route in a variable.
Every change is published right away to all of the project's domains.
Navigation mode
The mode only matters when the project (or the domain) has routes, like /prices → /pricing. A SPA
router picks the screen from the address in the browser's address bar. If a route masks the address, the visitor
sees /prices but the app only knows /pricing, and may show its own "page not found" screen.
| Mode | How it works | When to use it |
|---|---|---|
| Mask (default) | Each route follows its own mode; with rewrite routes the visitor always sees the customer's domain and friendly path | Traditional sites, server-rendered apps, SPAs without routes or that already know the friendly paths |
| Redirect | Every route in the project becomes a redirect (302) to the destination path, on the same customer domain | SPAs that get lost with a masked address |
In Redirect mode, whoever opens customer.com/prices is sent to customer.com/pricing: the domain stays the
customer's, only the path changes, and the app's router finds the right screen. The redirect applies to GET
requests (opening pages); POST, PUT and the like are still rewritten without redirecting.
Initial route in a variable
Want to keep the masked address and open the right screen? Turn on Send initial route in a variable. When a
route rewrites the path, the edge adds this at the top of the page's <head>:
<script>window.TENANCI_INITIAL_ROUTE="/pricing";</script>The value is the path (with parameters) the origin received. Your app just reads the variable on startup and navigates to it. Without a rewritten route, the variable isn't set.
// before mounting the app
const initial = window.TENANCI_INITIAL_ROUTE;
if (initial) router.replace(initial); // vue-router; with React Router: navigate(initial, { replace: true })import 'dart:js_interop';
@JS('TENANCI_INITIAL_ROUTE')
external String? get tenanciInitialRoute;
final router = GoRouter(initialLocation: tenanciInitialRoute ?? '/', routes: [/* ... */]);HTML cache for SPAs
In a SPA the HTML is usually the same for every visitor (the data arrives later through the API). That's the ideal case for the domain's HTML cache: the edge answers instantly, even when the app server is slow or "asleep". Turn it on in the domain's Settings tab, Performance card. Details and caveats in Performance and caching.
Deep links and 404s
The edge forwards each path to the origin as it came in: someone opening customer.com/courses/42 directly (or
hitting refresh) asks the origin for /courses/42. The app's host must answer with index.html for SPA routes (the
"fallback rule": rewrites on Vercel, _redirects on Netlify, try_files on nginx). Most AI app builders already
publish this way.
Tenanci keeps the origin's status code. If the host serves the app with a 404 status on internal routes, the
visitor sees the screen, but Google treats the page as missing and the HTML cache won't store the response (it only
stores 200). Fix it on the host so it returns 200.
Files from other addresses
If the app loads public files from another address of yours (a CDN, an image bucket), add that host under Extra
origins on the same Overview tab: references to it are then served through the customer's domain. For safety,
cookies and the Authorization header are never forwarded to extra origins, so use it for public files, not for the
app's authenticated API. See Projects.
Via the API
Mode and variable are project fields in PATCH /projects/:id: spaMode (mask or
redirect) and spaInitialRouteVar (true or false). The current values are under spa in
GET /projects/:id.
curl -X PATCH https://api.tenanci.com/v2/projects/prj_8f3k2m \
-H "Authorization: Bearer tnc_live_xxxxxxxx_xxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{"spaMode":"mask","spaInitialRouteVar":true}'await tenanci.request("PATCH", "/projects/prj_8f3k2m", { spaMode: "mask", spaInitialRouteVar: true });
