Horje
useHistory() Code Example
useHistory()
import { useHistory } from 'react-router-dom';

function Home() {
  const history = useHistory();
  return <button onClick={() => history.push('/profile')}>Profile</button>;
}
useHistory
import { useNavigate } from 'react-router-dom';
const navigate = useNavigate();
navigate('/home');
useHistory react-router-dom
In react-router-dom version 6 
useHistory() is replaced by useNavigate() ;

import {useNavigate} from 'react-router-dom';
const navigate = useNavigate();
navigate('/home')
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
useHistory hook
// useHistory() does not work inside an arrow function 
// notice @ line 9 that the history.push() is inside a usual function. not an arrow function

let myComponent = () => {
    
const history = useHistory();
  function routeChange(){
   history.push("/author");
  }
  
  return(<>
  <button onClick={ routeChange} > redirect </button>
  </>)
    
}

      
      
      
      




Javascript

Related
google custom search 'Request contains an invalid argument. Code Example google custom search 'Request contains an invalid argument. Code Example
convert da decimale a hex javascript Code Example convert da decimale a hex javascript Code Example
sanitise string js Code Example sanitise string js Code Example
__v MONGODB Code Example __v MONGODB Code Example
typescript prevent node modules Code Example typescript prevent node modules Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7