reactjs – react-router链接打字稿错误
发布时间:2020-12-15 16:18:34 所属栏目:百科 来源:网络整理
导读:我刚开始在我的React项目中添加TypeScript,我无法弄清楚这个错误: import {Link} from 'react-router';Module '"/Users/.../node_modules/@types/react-router/index"' has no exported member 'Link'. Link组件存在于react-router中(代码正在运行),但TypeS
我刚开始在我的React项目中添加TypeScript,我无法弄清楚这个错误:
import {Link} from 'react-router'; Module '"/Users/.../node_modules/@types/react-router/index"' has no exported member 'Link'. Link组件存在于react-router中(代码正在运行),但TypeScript无法识别它.我添加了@ types / react-router,似乎没有实现Link.有任何想法吗 ? 从我的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", 解决方法
你有反应路由器版本3,但版本4的@types包.refer-router版本4将很多库移动到react-router-dom包中,这就是为什么他们的类型不在@ types / react-router v4包.
您应该删除不正确的类型包: npm un @types/react-router 然后安装正确的类型: npm i --save-dev @types/react-router@3 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |