跳到主要内容

常见 API 手册

useParams

// 动态参数
const { id } = useParams();

useNavigate

// 编程方式导航
const navigate = useNavigate();

useLocation

// 返回当前 Location。如果你想在 Location 发生变化时执行一些副作用,这将非常有用。
const location = useLocation();

matchPath

// 匹配路径
matchPath<ParamKey, Path>(pattern, pathname): PathMatch<ParamKey> | null

https://api.reactrouter.com/v7/functions/react_router.matchPath.html