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

1 Answers1

0

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>
            );
      }
    }  
Prabhu
  • 1,057
  • 7
  • 13
  • hi deva for the quick reply unfortunately it is not working could you please provide me some working exampleon programmatic redirect using react router in spfx?? many thanks' – prabhat katoch May 19 '18 at 20:06