问题描述
我正在使用 react-router 2.4.0
并想以编程方式链接到另一条路线(在使用< Link> )。
这个很好地解释了这个他们在 2.4.x
中说你应该使用装饰模式和 withRouter
,所以我使用以下代码:
从'react-router'导入{withRouter} //进一步导入省略
类CreateJobItemFormRaw扩展React.Component {
...
}
const CreateJobItemForm = withRouter(CreateJobItemFormRaw)
导出默认值CreateJobItemForm
然后在其他文件中,我使用
$ b从$ ./CreateJobItemForm'
$ >然而,通过这种方法,我的应用程序根本不再渲染和c onsole输出:
CreateJobItemForm.js:76 Uncaught TypeError:(0,_reactRouter.withRouter)不是函数
任何人都可以帮我解决这个问题吗?
我相信你实际上正在使用react-router 2.4.0,但在我的情况下,值得仔细检查我的package.json确实强制执行该版本。我修改了我的package.json:
dependencies:{
react-router:^ 2.4.0,
...
}
希望这会有所帮助。
I am using react-router 2.4.0
and want to link to another route programmatically (what I did before using <Link>
).
It's explained nicely in this SO post where they say in 2.4.x
you should use the decorator pattern with withRouter
, so I am using the following code:
import {withRouter} from 'react-router' // further imports omitted
class CreateJobItemFormRaw extends React.Component {
...
}
const CreateJobItemForm = withRouter(CreateJobItemFormRaw)
export default CreateJobItemForm
Then in other files, I use
import CreateJobItemForm from './CreateJobItemForm'
However, with this approach my app doesn't render at all any more and the console outputs:
CreateJobItemForm.js:76 Uncaught TypeError: (0 , _reactRouter.withRouter) is not a function
Can anyone help me solve this?
I trust that you are in fact using react-router 2.4.0, but in my case it was worth double-checking that my package.json did in fact enforce that version. I modified my package.json as such:
"dependencies": {
"react-router": "^2.4.0",
...
}
Hope this helps.
这篇关于未捕获的TypeError:(0,_reactRouter.withRouter)在反应路由器2.4.0中以编程方式导航到路由时不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!