Answers for "useHistory back"

1

useHistory goback

import {useHistory} from "react-router-dom";

const history = useHistory();

<button onClick={() => history.goBack()}>Go Back</button>
Posted by: Guest on November-30-2020
3

react router dom current path hook

import { useLocation } from 'react-router-dom'

// Location is, for example: http://localhost:3000/users/new

// Care! MyComponent must be inside Router to work
const MyComponent = () => {
	const location = useLocation()
    
    // location.pathname is '/users/new'
    return <span>Path is: {location.pathname}</span>
}

export default MyComponent
Posted by: Guest on June-12-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language