Skip to main content

useHref

还没翻译译自英文(reactrouter.com)本页 15 段都还没译

useHref

Framework Data Declarative

Summary

Reference Documentation ↗

Resolves a URL against the current Location.

import { useHref } from "react-router";

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

Signature

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

Params

to

The path to resolve

options.relative

Defaults to "route" so routing is relative to the route tree. Set to "path" to make relative routing operate against path segments.

Returns

The resolved href string

Traducción © 2026 fanyi.dev · Original © 2026 React Training LLC, Remix Software Inc., Shopify Inc. (MIT)