Skip to content

Instantly share code, notes, and snippets.

@richleach
Created April 21, 2021 21:22
Show Gist options
  • Save richleach/a52c8e2184332b8da2ea15b63da1e80e to your computer and use it in GitHub Desktop.
Save richleach/a52c8e2184332b8da2ea15b63da1e80e to your computer and use it in GitHub Desktop.
Programmatic navigation using useHistory (like cflocation works)
import { useHistory } from 'react-router-dom';
function MyFunction() {
const history = useHistory();
//execute some code, maybe call an API, then redirect to the home page
history.replace('/');
}
export default MyFunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment