I have run out of wisdom on this issue and hope for any ideas that could bring me on the right track.
I have implemented a React.js SPA that uses react-router-dom v6 to navigate through the app functions. The App works flawlessly on my localhost. When deployed to production the <Route ... /> renders nothing.
I have checked that the deployment path is correct by rendering an <h2> element outside the <Routes> ... </Routes>.
App.js
import React from 'react';
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom';
const App = () => {
const title = `${(process.env.REACT_APP_TITLE)}`;
const TwentyfourStats = () => (<h2>Works</h2>);
return (
<Router>
<div id="app" className="App">
<h2>{title}</h2>
<div>
<Routes>
<Route path="/" element={<TwentyfourStats />} />
</Routes>
</div>
</div>
</Router>
);
}
export default App;
I have tried setting <Routes homebase={}> while adjusting "homepage": "..." in package.json but it made no difference.
Many thanks
UPDATE: I have inlined the component <TwentyfourStats /> in the example to remove any deps on folder structure. The result is the same.
UPDATE 2: The problem is solved, as pointed by @VitaliyRayets by using HashRouter instead of BrowserRouter (see answer).