Uncaught TypeError:(0,_reactRouter.withRouter)在react-router 2.4.0中编程路由导航时不是函数
我正在使用react-router 2.4.0
并想以编程方式链接到另一个路由(我使用<Link>
之前做了什么)。
在这个SOpost里很好的解释了他们在2.4.x
说你应该在withRouter
使用装饰器模式,所以我使用下面的代码:
import {withRouter} from 'react-router' // further imports omitted class CreateJobItemFormRaw extends React.Component { ... } const CreateJobItemForm = withRouter(CreateJobItemFormRaw) export default CreateJobItemForm
然后在其他文件中,我使用
import CreateJobItemForm from './CreateJobItemForm'
但是,使用这种方法,我的应用程序不再渲染和控制台输出:
CreateJobItemForm.js:76 Uncaught TypeError: (0 , _reactRouter.withRouter) is not a function
谁能帮我解决这个问题吗?
我相信你实际上正在使用react-router 2.4.0,但在我的情况下,值得仔细检查一下,我的package.json实际上是否强制执行该版本。 我修改我的package.json是这样的:
"dependencies": { "react-router": "^2.4.0", ... }
希望这可以帮助。
在对此问题链接的另一个答案的评论中,并表示您正在尝试使用react-router 2.4+进行导航。 尝试并将PropType规范放在文件中,看看是否给你任何警告。 例如:
// PropTypes Example.propTypes = { router: React.PropTypes.shape({ push: React.PropTypes.func.isRequired }).isRequired };
import { withRouter } from 'react-router-dom' react-router v4.x