$ yarn add react-router-dom
import {
BrowserRouter as Router,
Link,
Route,
Switch,
useHistory,
useParams,
} from 'react-router-dom';
export default function App() {
return (
<Router>
<Link to="/example1">
Example 1
</Link>
<Switch>
<Route path="/example2/id">
<Example2 />
</Route>
</Switch>
</Router>
);
}
const { id } = useParams();
const history = useHistory();
history.push('/path');
history.replace('/path');