简体   繁体   中英

react-router Link typescript error

I just started to add TypeScript on my React project, and I can't figure out of this error :

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. I've added the @types/react-router , and it seems not to implements the Link . Any ideas ?

Extract from my 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM