useHref
根據目前位置解析完整的 URL,以便作為 href
使用於 link
。如果提供相對路徑,它將解析為完整的 URL。
import { useHref } from "@remix-run/react";
function SomeComponent() {
const href = useHref("some/where");
return <a href={href}>Link</a>;
}
useHref(to, options)
to
可選。要附加到解析 URL 的路徑。
useResolvedPath
文件中關於 Splat 路徑的部分,以了解 splat 路由中相對 useHref()
行為的 future.v3_relativeSplatPath
未來標誌的注意事項
options
唯一的選項是 { relative: "route" | "path"}
,它定義了解析相對 URL 時的行為。
..
將移除一個 URL 段。