useHref
本页内容

useHref

摘要

参考文档 ↗

根据当前 Location 解析 URL。

import { useHref } from "react-router";

function SomeComponent() {
  let href = useHref("some/where");
  // "/resolved/some/where"
}

签名

function useHref(
  to: To,
  {
    relative,
  }: {
    relative?: RelativeRoutingType;
  } = ,
): string {}

参数

to

要解析的路径

options.relative

默认为 "route",因此路由是相对于路由树的。设置为 "path" 可使相对路由操作针对路径段进行。

返回

解析后的 href 字符串

文档和示例 CC 4.0
编辑