I created an app using react js , then i deployed it to a server but when i access it i found a blank page with no error message . I searched google and other related issue in stackoverflow and i tried their solution but I still have the blank page . then I changed BrowserRouter to HashRouter in this case it works but at some point the following error appeared : error message image
( i think i can fix it with few changes in the code )
but I don't want to use HashRouter , is there any other possibility to make it work ( no blank page ) using BrowserRouter ?
package.json :
{
"name": "flowdia_react_version",
"homepage": ".",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.3",
"serve": "^12.0.0",
"web-vitals": "^1.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
index.js :
import React from "react";
import ReactDOM from "react-dom";
import App from "./App";
import { BrowserRouter as Router } from "react-router-dom";
ReactDOM.render(
<React.StrictMode>
<Router forceRefresh={true} >
<App />
</Router>
</React.StrictMode>,
document.getElementById("root")
);
app.js :
import "./dist/css/style.css";
import { Switch, Route } from "react-router-dom";
import Questions from "./components/questions/Questions";
import StartPage from "./components/StartPage";
import Output from "./components/Output";
import HomeCare from "./components/HomeCare";
const App = () => {
return (
<Switch>
<Route path="/" exact children={<StartPage />} />
<Route path="/questions" children={<Questions />} />
<Route path="/output" children={<Output />} />
<Route path="/home-care" children={<HomeCare />} />
</Switch>
);
};
export default App;