score:-1
Remove 'exact' from your routes props.
score:1
You can simply use the useHistory
hook from react-router-dom
import { useHistory } from "react-router-dom";
const history = useHistory();
...
<div onClick={ ()=>history.goBack() }>Back </div>
score:8
You can achieve this by calling goBack()
function in history
object inside withRouter()
.
import React from 'react';
import { withRouter } from 'react-router-dom'
export default withRouter(({ history }) => {
return (
<div>
<button onClick={() => history.goBack()}>BACK</button>
</div>
)
});
Source: stackoverflow.com
Related Query
- React Router - Go back to the last page visited, and not the default component
- How to make a nested react router component load to a new page and not half-way down the page
- React router 4 `Link` component only changing the url and not updating the route
- React Router v4 redirect to current page and the component disappears
- React Router v6 Link component not changing the page at root url
- Not found page and default home page always redirect to home - React Router
- Testing <Input/> component from Material UI using Testing React Library and the call back function is not recongnized in the onChange prop
- The default export is not a React Component in page: "/" NextJS
- react router not rendering the component
- React router is not reloading page when url matches the same route
- React router - pass api data to the linked component to open with a new page
- React Router v5: history.push() changes the address bar, but does not change the page
- React Router <Link> and <Route> not passing state to Component
- react router changes the URL, but the component is not rendered
- how to update a route in React Router without re-mounting the component in a single page app?
- React Router this.context.router.push does not remount the component
- React Router doesn't load the new page component after redirecting via navigate
- I can not get the state from react router Link component using useLocation. So how can I pass it?
- How to add type FunctionComponent to React functional component using the "function" syntax and not "const"?
- React router redirects the page but component doesn't get rendered
- React Router not showing the component
- React Router v4: Component and Children in the same route
- creating common header and sidebar across all the page using react router
- React Router "Link to" does not load new data when called from inside the same component
- React Router V4 - Route between components and not entire page
- react prop not rendering in parent component and even in the same one
- React router dom passing data from parent component to child router component does not pass the props.match
- The last 'SetItem' is not saved and clears when the page is Refresh
- React Router V5 not rendering route when clicking Link, but back and forward buttons work?
- React Router will not render Route component unless page is refreshed
More Query from same tag
- React - how call function parent from grandchild
- Understanding withtracker() component in Meteor
- Simulating a Div Click on Enzyme and React
- Next-Auth: Cannot read property 'Adapter' of undefined
- React Class Component not working properly for me
- How can you only filter by the specific object clicked?
- handling arrays in javascript
- How to handle conditional redirect in react app routes?
- How to show value calculated from input form to the screen
- How to concatenate a new item with hooks in react js?
- importing css of react-toastify in react SSR throwing error
- Does Enzyme test utility work with React.createClass?
- failed to concat nested array of object in setState of react
- how return value form use hook
- Using React hooks to set state and local storage and React is saying I am making too many calls
- React JS Bootstrap not applied
- Why is the data not updated with useState when I do a map on another array of object?
- How to update state in react synchronously
- React useRef not updating consistently for conditionally rendered elements
- How to use API color variable in css file?
- How to restrict user input from 0 to 99 in JavaScript
- How to rebuild a existing Dom in reactjs?
- React Recoil state not being reset properly
- react-router how to configure the index route using Javascript object?
- React Hooks: State is resetting to empty array even if I use the spread operator, prevState, etc
- How to replace plus minus toggle with checkbox(tick untick) in HTML CSS?
- ReactJS Adjacent JSX elements must be wrapped in an enclosing tag
- How to load image from shared file on local server?
- Zip files / folders / zips from Remote URLs with JSZip
- TypeError: Cannot read property '0' of undefined in react