Make routing work from a file-served bundle (React Router 6 under Capacitor) #24

Closed
opened 2026-07-26 04:54:41 -07:00 by westfarn · 0 comments
Owner

Risk

Blocks #20 (Android) and #21 (iOS).

The app uses React Router 6 with BrowserRouter. On the web, nginx rewrites unknown paths to index.html, so a reload at /chat/123 works. Under Capacitor the bundle is served from the local filesystem with no rewrite rule, so any load or reload at a nested path can resolve to a missing file and produce a blank screen or a 404. Anything that triggers a full reload (crash recovery, WebView restart after memory pressure, an external link back into the app) hits this.

Work

  • Reproduce: build with Capacitor, launch directly at a nested route, and force a WebView reload.
  • Pick a fix: HashRouter for native, createMemoryRouter, or Capacitor server.androidScheme / errorPath config that falls back to index.html.
  • Avoid divergence between web and native routers if possible; if the router differs by platform, isolate it in one place rather than sprinkling Capacitor.isNativePlatform() checks through the route tree.
  • Check every absolute-path assumption: PUBLIC_URL, asset paths, hardcoded / links, redirects after login, and anything calling window.location.
  • Confirm relative asset paths in the CRA build (homepage field) so JS/CSS/fonts load from the bundled origin.
  • Verify browser back/forward and the Android hardware back button behave with the chosen router.
  • Sanity check that the web deploy under /var/www/{env}.chat.aimloperations/html is unaffected by the change.

Done when

Every route loads and reloads cleanly in a Capacitor build on both platforms, assets resolve, and the web build behaves exactly as before.

## Risk Blocks #20 (Android) and #21 (iOS). The app uses React Router 6 with `BrowserRouter`. On the web, nginx rewrites unknown paths to `index.html`, so a reload at `/chat/123` works. Under Capacitor the bundle is served from the local filesystem with no rewrite rule, so any load or reload at a nested path can resolve to a missing file and produce a blank screen or a 404. Anything that triggers a full reload (crash recovery, WebView restart after memory pressure, an external link back into the app) hits this. ## Work - [ ] Reproduce: build with Capacitor, launch directly at a nested route, and force a WebView reload. - [ ] Pick a fix: `HashRouter` for native, `createMemoryRouter`, or Capacitor `server.androidScheme` / `errorPath` config that falls back to `index.html`. - [ ] Avoid divergence between web and native routers if possible; if the router differs by platform, isolate it in one place rather than sprinkling `Capacitor.isNativePlatform()` checks through the route tree. - [ ] Check every absolute-path assumption: `PUBLIC_URL`, asset paths, hardcoded `/` links, redirects after login, and anything calling `window.location`. - [ ] Confirm relative asset paths in the CRA build (`homepage` field) so JS/CSS/fonts load from the bundled origin. - [ ] Verify browser back/forward and the Android hardware back button behave with the chosen router. - [ ] Sanity check that the web deploy under `/var/www/{env}.chat.aimloperations/html` is unaffected by the change. ## Done when Every route loads and reloads cleanly in a Capacitor build on both platforms, assets resolve, and the web build behaves exactly as before.
westfarn added a new dependency 2026-07-26 04:55:28 -07:00
westfarn added a new dependency 2026-07-26 04:55:29 -07:00
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Reference: ai_ml_operations/chat_web_app#24