import React, { Component } from 'react';
import { Navigate } from 'react-router-dom';
class MyComponent extends Component {
state = {
redirect: false
}
handleClick = () => {
this.setState({ redirect: true });
}
render() {
if (this.state.redirect) {
return <Navigate to='/dashboard' />;
}
return (
<div>
<h1>My Component</h1>
<button onClick={this.handleClick}>Go to Dashboard</button>
</div>
);
}
}
export default MyComponent;