Try this approach
import { useNavigate } from 'react-router-dom';
function YourApp() {
const navigate = useNavigate();
return (
<>
<button onClick={() => navigate(-1)}>go back</button>
</>
);
}
More Related Contents:
- React : difference between and
- How to create a protected route?
- React-router-v6 access a url parameter
- React Router v4 renders multiple routes
- How to pass params into link using React router v6?
- react-router-dom v6 useNavigate passing value to another component
- Detect Route Change with react-router
- Simple Conditional Routing in Reactjs
- Cannot read property ‘history’ of undefined (useHistory hook of React Router 5)
- Invariant failed: You should not use outside a
- useNavigate() may be used only in the context of a component
- React Router Dom v6 shows active for index as well as other subroutes
- React – TypeError: Cannot read properties of undefined (reading ‘params’)
- Error: useHref() may be used only in the context of a component. It works when I directly put the url as localhost:3000/experiences
- react app showing empty page when redirecting on production build
- React App goes blank after importing React-Router-Dom
- React Router 4 Nested Routes not rendering
- Children won’t render when using a layout in ReactJS
- React Router V6 – Error: useRoutes() may be used only in the context of a component
- react router v6 navigate outside of components
- Problem in redirecting programmatically to a route in react router v6
- react router difference between component and render
- How do I pass state through React_router?
- React-Router open Link in new tab
- ReactJS: [Home] is not a component. All component children of must be a or
- Performing Authentication on Routes with react-router-v4
- React router 4 does not update view on link, but does on refresh
- React: Hide a Component on a specific Route
- React: ‘Redirect’ is not exported from ‘react-router-dom’
- React Router v4 with multiple layouts