React Router renders a blank page because the URL does not start with the basename
Your error
<Router basename="/app"> is not able to match the URL "/" because it does not start with the basename, so the <Router> won't render anything.1 more line it can showFix it fast
Most common cause, 1 of 3HashRouter was given the folder the app is served from
Drop the basename from HashRouter.
import { HashRouter, Routes, Route } from "react-router";
<HashRouter>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/orders" element={<Orders />} />
</Routes>
</HashRouter>Short answer
The warning <Router basename="/app"> is not able to match the URL ... so the <Router> won't render anything means the path the router reads does not begin with its basename. HashRouter reads that path from the part after #, so a basename meant for the server folder never matches. Remove it there, or align BrowserRouter's basename and slash with the real path. Applies to React Router 6-8.
Which cause do you have?
Copy the URL inside the warning and compare it with where the browser really is. If it equals the part after # while the folder sits before #, that is cause 1. If it equals location.pathname and lacks the basename, cause 2. If it is the basename without its last slash, cause 3.
console.log({ pathname: location.pathname, hash: location.hash })Then find the line you see in this list and open its fix:
- 1HashRouter was given the folder the app is served from
The browser shows /app/#/ or /app/#/orders, and the warning reports the URL as / or /orders - 2BrowserRouter's basename differs from the path in the address bar
The warning's URL is the same as location.pathname, for example / on the dev server while basename is /app - 3The basename ends with a slash that the URL lacks
basename is /app/ and the browser is on /app, so the warning reports "/app"
What does the error look like?
<Router basename="/app"> is not able to match the URL "/" because it does not start with the basename, so the <Router> won't render anything.HashRouter basename not working, the page stays blank
Cause 1 of 3
HashRouter was given the folder the app is served from
You seeThe browser shows /app/#/ or /app/#/orders, and the warning reports the URL as / or /orders
Check
A basename on HashRouter causes this warning whenever the basename names the server folder. HashRouter stores its route after the # sign, a piece of the address that never reaches the server, and React Router parses its pathname out of window.location.hash. The /app folder in front of # is not part of that path, so /orders never starts with /app.
grep -rn "<HashRouter" src/Fix
Drop the basename from HashRouter. The routes work from whatever folder serves index.html, because only the hash is matched.
import { HashRouter, Routes, Route } from "react-router";
<HashRouter>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/orders" element={<Orders />} />
</Routes>
</HashRouter>Verify
Open https://example.com/app/#/orders: the Orders page renders and the console has no basename warning.
console.log(document.querySelector('#root').childElementCount > 0)Confirmed by reactrouter.com
Cause 2 of 3
BrowserRouter's basename differs from the path in the address bar
You seeThe warning's URL is the same as location.pathname, for example / on the dev server while basename is /app
Check
With BrowserRouter the warning means the real path does not begin with the basename. It shows up when basename is hard-coded to the production folder while the dev server serves the app at /, or after the app moves to another folder. The router then returns null, so nothing below it renders.
grep -rn "basename=\|base:" src/ vite.config.*Fix
Set the folder once, in Vite's base option, and pass the same value to the router through import.meta.env.BASE_URL. Strip the trailing slash that BASE_URL carries, for the reason in cause 3.
// vite.config.js
export default defineConfig({ base: '/app/' });
// main.jsx
import { BrowserRouter } from "react-router";
<BrowserRouter basename={import.meta.env.BASE_URL.replace(/\/$/, '')}>
<App />
</BrowserRouter>Verify
npm run dev opens the app under /app/, and a production build served from /app/ renders the same routes.
npm run build && npx vite previewConfirmed by vite.dev
Cause 3 of 3
The basename ends with a slash that the URL lacks
You seebasename is /app/ and the browser is on /app, so the warning reports "/app"
Check
React Router keeps a trailing slash on basename so you can control trailing-slash rules, and its stripBasename check then requires the path to start with /app/ including that slash. A visit to /app has no slash after the folder name, so the match fails. Letter case is not the problem here: both sides are lowercased before the comparison.
grep -rn "basename=" src/Fix
Write the basename without a trailing slash. /app then matches /app, /app/ and /app/orders.
<BrowserRouter basename="/app">
<App />
</BrowserRouter>Verify
Load /app and /app/ in turn: both render the home route without the warning.
console.log(location.pathname)Confirmed by raw.githubusercontent.com
How do I stop it coming back?
- Derive the router basename from the bundler's base setting instead of typing the folder in two places.
- Pick one router per deployment: HashRouter for hosts that cannot rewrite unknown paths, BrowserRouter with a basename when they can.
- Open the deployed build once under its real folder before release, since the dev server at / hides a wrong basename.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine on the same stack: TaxiDex, QistLock, Taskvare.