Reactjs 在解析承诺后更改路径时,是否需要导入PropType并定义ContextType?

Reactjs 在解析承诺后更改路径时,是否需要导入PropType并定义ContextType?,reactjs,react-router,react-router-v4,Reactjs,React Router,React Router V4,在react路由器v2和v3中,我们可以 import React, { Component, PropTypes } from "react"; class PostsNew extends Component { static contextTypes = { router: PropTypes.object } handleUserSubmit(props) { this.props.createPost(props) .then(() =&g

在react路由器v2和v3中,我们可以

import React, { Component, PropTypes } from "react";

class PostsNew extends Component {

  static contextTypes = {
    router: PropTypes.object
  }

  handleUserSubmit(props) {
    this.props.createPost(props)
      .then(() => {
        // the post has been created successfully
        // now route back to index
        this.context.router.push("/");
      });
  }

  // ...
但是在react router v4中,如果我们只需要
这个.props.history.push()
而不是使用
上下文

  handleUserSubmit(props) {
    this.props.createPost(props)
      .then(() => {
        // the post has been created successfully
        // now route back to index
        this.props.history.push("/");
      });
  }

那么我们是否可以跳过导入
PropTypes
和定义
contextTypes
?所以改变路径将像
this.props.history.push(“/”)一样简单如果我们使用react路由器v4?

是。或者您可以使用组件。

您的意思是“是的,我们仍然需要使用
PropTypes
contextTypes
”还是“是的,那么我们不需要使用
PropTypes
contextTypes
”?我们可以跳过PropTypes的导入和contextTypes的定义吗?对