I want to remove the # Hash from the url using React Router dom. I came across the solution of putting the browserrouter around the switch with the routes, which seems to only work when you change between tabs, but when reloading or loading the site initially the # still appears
My Router Code
return (
<BrowserRouter>
<Switch>
{!authCtx.isLoggedIn && (
<Route
exact
path="/"
component={() => (
<Home />
)}
/>
)}
{!authCtx.isLoggedIn && (
<Route path="/Login" component={() => <Login />} />
)}
{authCtx.isLoggedIn && (
<Route
path="/EmployeeHome"
component={() => (
<EmployeeHome />
)}
/>
)}
{authCtx.isLoggedIn && (
<Route path="/Appointment">
<Redirect to="/EmployeeHome" />
</Route>
)}
{authCtx.isLoggedIn && (
<Route path="/Documentations" component={() => <Documentations />} />
)}
{authCtx.isLoggedIn && (
<Route
path="/Statistic"
component={() => (
<Statistics />
)}
/>
)}
<Route path="*">
{authCtx.isLoggedIn && <Redirect to="/Appointment" />}
{!authCtx.isLoggedIn && <Redirect to="/" />}
</Route>
</Switch>
</BrowserRouter>);
HashRouter? If so, then don't use aHashRouter, use one of the other high-level routers, e.g.BrowserRouter. Also, if you are using more than one router, don't. You really only need one router near the root of your app to provide a routing context for all routing/navigation components/hooks/etc... Remove all extraneous routers. You're using RRDv5 it seems, which allows you to nest routers, but it isn't recommended, and actually throws an invariant error in later version. Can you update your question to include all relevant routing & navigation code?