0

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>
        );
  }
}  
4

1 に答える 1

0

このように使用できます

    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>
            );
      }
    }  
于 2018-05-19T12:01:23.673 に答える