This has changed in v6, useHistory is now useNavigate and we can use it as follows:
instead of:
const history = useHistory()
history.push("https://stackoverflow.com/")
we now use:
const navigate = useNavigate()
navigate("https://stackoverflow.com/")
More Related Contents:
- Link tag inside BrowserRouter changes only the URL, but doesn’t render the component
- How to pass data from a page to another page using react router
- How do I render components with different layouts/elements using react-router-dom v6
- react router v6 navigate outside of components
- Problem in redirecting programmatically to a route in react router v6
- Error: [PrivateRoute] is not a component. All component children of must be a or
- React doesn’t reload component data on route param change or query change
- Uncaught TypeError: Cannot read property ‘push’ of undefined (React-Router-Dom)
- ReactJS – Pass props with Redirect component
- Multiple Nested Routes in react-router-dom v4
- How do you pass data when using the navigate function in react router v6
- how to listen for route change in react-router-dom v6
- ReactJS: [Home] is not a component. All component children of must be a or
- Error “Error: A is only ever to be used as the child of element”
- How to create a protected route with react-router-dom?
- react-router-dom v6 Routes showing blank page
- using history with react-router-dom v6
- React Router Dom routes are returning blank pages
- React router dom: Route and Router not working at all
- React: ‘Redirect’ is not exported from ‘react-router-dom’
- How can I redirect in React Router v6?
- useMemo vs. useEffect + useState
- JSX not allowed in files with extension ‘ .js’ with eslint-config-airbnb
- Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null [closed]
- React.js best practice regarding listening to window events from components
- how to render child components in react.js recursively
- React Warning: flattenChildren(…): Encountered two children with the same key
- TypeError: Cannot read properties of undefined (reading ‘call’) on Next.js
- Updating state to the same value directly in the component body during render causes infinite loop
- Preserve Type when using Object.entries