Reputation: 13
import * as React from 'react'; import { browserHistory } from "react-router-dom" import Title from './app'
**export default class TestRoute extends React.Component<ITestRouteProps, {}> {
handleClick = () => {
browserHistory.push('/Title')
};
public render(): React.ReactElement<ITestRouteProps> {
return (
<div>
<h1>Simple SPA</h1>
<button onClick={this.handleClick} type="button">/*this shoult take me to another page
click me </button>
</div>
);
}
}
Upvotes: 0
Views: 1761
Reputation: 1057
You can use like this
import PropTypes from 'prop-types';
static contextTypes = {
router: PropTypes.object,
}
export default class TestRoute extends React.Component<ITestRouteProps, {}> {
handleClick = () => {
this.context.router.history.push('/Title')
};
public render(): React.ReactElement<ITestRouteProps> {
return (
<div>
<h1>Simple SPA</h1>
<button onClick={this.handleClick} type="button">/*this shoult take me to another page
click me </button>
</div>
);
}
}
Upvotes: 0