[英]react-router Link typescript error
I just started to add TypeScript on my React project, and I can't figure out of this error : 我刚开始在我的React项目中添加TypeScript,我无法弄清楚这个错误:
import {Link} from 'react-router';
Module '"/Users/.../node_modules/@types/react-router/index"' has no exported member 'Link'.
The Link
component exists in react-router
(the code is working), but TypeScript does not recognise it. Link
组件存在于react-router
(代码正在运行),但TypeScript无法识别它。 I've added the @types/react-router
, and it seems not to implements the Link
. 我添加了
@types/react-router
,似乎没有实现Link
。 Any ideas ? 有任何想法吗 ?
Extract from my package.json
: 从我的
package.json
提取:
"@types/react": "^15.0.25",
"@types/react-dom": "^15.5.0",
"@types/react-router": "^4.0.11",
"@types/reactstrap": "^4.3.4",
...
"react": "^15.4.2",
"react-dom": "^15.4.2",
"react-router": "^3.0.2",
"reactstrap": "^4.2.0"
...
"typescript": "^2.3.3",
You have react-router
version 3, but the @types package for version 4. Version 4 of react-router moved a lot of the library into the react-router-dom
package, which is why their types are not in the @types/react-router
v4 packages. 你有
react-router
版本3,但版本4的@types包.refer react-router
版本4将很多库移动到react-router-dom
包中,这就是为什么他们的类型不在@types/react-router
v4包。
You should remove the incorrect type package with: 您应该删除不正确的类型包:
npm un @types/react-router
Then install the correct types with: 然后安装正确的类型:
npm i --save-dev @types/react-router@3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.