Answers for "react router dom programmatically change route"

0

Programmatically navigate using react router

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

function HomeButton() {
  let history = useHistory();

  function handleClick() {
    history.push("/home");
  }

  return (
    <button type="button" onClick={handleClick}>
      Go home
    </button>
  );
}
Posted by: Guest on November-28-2019
1

react router change route from function

import {withRouter} from 'react-router-dom';
this.props.history.push('route');
export default withRouter(your component name)
the react component should be wrapped with withRouter hoc 
so that history will work
Posted by: Guest on March-07-2021

Code answers related to "react router dom programmatically change route"

Code answers related to "Javascript"

Browse Popular Code Answers by Language