Answers for "change the route on button click react"

4

navigating programatically react

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

const Button = () => (
  <Route render={({ history}) => (
    <button
      type='button'
      onClick={() => { history.push('/new-location') }}
    >
      Click Me!
    </button>
  )} />
)
Posted by: Guest on July-01-2020
0

change the route on button click react

class Login extends Component {
    nextPath(path) {
    this.props.history.push(path);
  }
    render() {
        return (
        <div>
        <button type='button' onClick={() => this.nextPath('/yourpath') } >Button</button>
        </div>
        );
}
Posted by: Guest on October-27-2021

Code answers related to "change the route on button click react"

Code answers related to "Javascript"

Browse Popular Code Answers by Language