You should use your own router with react-router-dom
to do this. I preferably use HashRouter.
(What is the difference between HashRouter and BrowserRouter in React?)
Here is a simple example for routing in App.js;
import { HashRouter as Router, Route, Switch } from 'react-router-dom';
// Components
import Homepage from './components/Homepage';
import AboutMe from './components/AboutMe';
import Error404 from './components/Error404';
export default function App() {
return (
<Router>
<Switch>
<Route key="homepage" exact path={['/', '/homepage']}>
<Homepage />
</Route>
<Route key="aboutme" exact path="/aboutme">
<AboutMe />
</Route>
<Route path="*">
<Error404 />
</Route>
</Switch>
</Router>
);
}
After that when you go /aboutme
you will see AboutMe component or when you go /
or /homepage
you will see Homepage component. If you try to go /blabla
like this you will see Error404 component.