useLocation()只能在<Router>组件的上下文中使用。

报错信息:

useLocation() may be used only in the context of a component.

解决方法:

引入useLocation方式:

import { useLocation } from "react-router";

改为

import { useLocation } from "react-router-dom";

参考:javascript - React js:错误:useLocation() 只能在 组件的上下文中使用 - SegmentFault 思否

你可能感兴趣的:(React,前端,前端,javascript)