Try this approach
import { useNavigate } from 'react-router-dom';
function YourApp() {
const navigate = useNavigate();
return (
<>
<button onClick={() => navigate(-1)}>go back</button>
</>
);
}
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
- React Router Dom v6 shows active for index as well as other subroutes
- Cannot read property ‘history’ of undefined (useHistory hook of React Router 5)
- useNavigate() may be used only in the context of a component
- 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 – TypeError: Cannot read properties of undefined (reading ‘params’)
- Invariant failed: You should not use outside a
- React App goes blank after importing React-Router-Dom
- react app showing empty page when redirecting on production build
- React Router 4 Nested Routes not rendering
- React Router V6 – Error: useRoutes() may be used only in the context of a component
- Programmatically navigate using React router
- How to push to History in React Router v4?
- react router v6 navigate outside of components
- How to get history on react-router v4?
- react router difference between component and render
- Detecting user leaving page with react-router
- Component does not remount when route parameters change
- Programmatically navigating in React-Router v4
- React doesn’t reload component data on route param change or query change
- What is the best way to redirect a page using React Router? [closed]
- 404 when trying to enter a react app route
- How to stop /#/ in browser with react-router?
- You should not use outside a
- React Router v4 – How to get current route?
- Nesting Routes in react-router v4
- React Router not working with Github Pages
- Uncaught TypeError: Cannot read property ‘push’ of undefined (React-Router-Dom)
- react router v4 default page(not found page)
- Why do I get the error “expressions must have one parent element”, how do I fix this?
- React router v6 how to use `navigate` redirection in axios interceptor
- How to tell webpack dev server to serve index.html for any route
- How to use Private route in react-router-dom@v6
- Performing Authentication on Routes with react-router-v4
- What is withRouter for in react-router-dom?
- React-Router open Link in new tab
- react-router-dom useParams() inside class component
- Difference in the navigation (React Router v6)
- react router v6 No routes matched location
- Nested Routes not rendering with React Router v4
- react-router vs react-router-dom, when to use one or the other?
- Pass object through Link in react router
- Use history.push in action creator with react-router-v4?