React version:
"react": "^16.13.0",
"react-dom": "^16.13.0",
"react-router-dom": "5.0.1",
"react-scripts": "3.4.0",
js代码为
import {useLocation} from "react-router-dom";
const location = useLocation();
……问题在哪里?
该钩子是在5.1.0中添加的。
尝试卸载并重新安装" react-router-dom ";然后,为安全起见,运行npm i
和npm start
。此外,如果你使用的是TS,你还必须安装"@types/react-router-dom"作为开发依赖