History-mode routers (React's BrowserRouter, Vue's createWebHistory, Angular's default) need a server that answers every path with index.html. A packaged app has no such server: it opens /web/index.html, so no route matches and reloads 404. Switch to hash routing — HashRouter or createHashRouter in React, createWebHashHistory in Vue, withHashLocation in Angular — and launch, reload and the back button all work.
Symptoms
| You see | Cause |
|---|---|
| Blank screen or "Not found" route on launch | No route matches /web/index.html |
| Pull-to-refresh shows an empty page | Reload requests /web/settings, which is not a file |
| Back button exits the app | Navigation used replace instead of push |
The fix, per framework
// React Router 6.4+
import { createHashRouter, RouterProvider } from 'react-router-dom';
const router = createHashRouter(routes);
<RouterProvider router={router} />
// Vue Router 4
import { createRouter, createWebHashHistory } from 'vue-router';
createRouter({ history: createWebHashHistory(), routes });
// Angular (standalone)
provideRouter(routes, withHashLocation());
// Svelte (svelte-spa-router is hash-based by default)
import Router from 'svelte-spa-router';URLs become index.html#/settings. The part after # never reaches the file server, so the app always loads index.html and the router reads the fragment.
If you must keep history mode
Set the router's basename to the page path at runtime and never reload:
const base = location.pathname.replace(/index\.html$/, '');
createBrowserRouter(routes, { basename: base });This handles launch, but a reload on a deep route still 404s. Hash routing is simpler and has no edge cases.
The Android back button
The app's back button calls the WebView's history back. Every push navigation adds an entry, so back walks your routes and exits only from the first screen — which is what Android users expect. Use replace only for redirects (such as after login), never for normal navigation.
Questions people ask
Why does my React app work on the web but not in the APK?
On the web your server rewrites every path to index.html; in the APK there is no such rewrite. Use HashRouter or createHashRouter.
Does hash routing hurt SEO?
Not for the app — app screens are not indexed by search engines. Keep history mode on the website build and use hash routing only in the APK build if you need both.
Will the back button work with hash routing?
Yes. Each hash navigation is a history entry, so Android's back button moves back through your routes.