简体   繁体   中英

Attempted import error: 'useLocation' is not exported from 'react-router-dom'

React version:
"react": "^16.13.0",
"react-dom": "^16.13.0",
"react-router-dom": "5.0.1",
"react-scripts": "3.4.0",

js code as

import {useLocation} from "react-router-dom";
const location = useLocation();

...... where is the problem?

该钩子是 在 5.1.0添加的

i am having the same isuue with react-router-dom version 6.6.1.any fixes???

Try uninstalling and reinstalling the "react-router-dom" Then, for safety, run npm i and npm start . Also, if you're using TS, you have to also install "@types/react-router-dom" as a dev dependency

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