首页 文章

使用 react 路由在 sharepoint 框架 webpart 中路由?我陷入了局势,我必须在按钮点击时重定向到另一个页面。

提问于
浏览
0

import * as React from'reaction'; import {{。 1}来自“react-router-dom”从'./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 回答

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

相关问题