useResolvedPath

概要

リファレンスドキュメント ↗

指定された to 値のパス名を現在の Location に対して解決します。useHref と似ていますが、文字列ではなく Path を返します。

import { useResolvedPath } from "react-router";
 
function SomeComponent() {
  // ユーザーが /dashboard/profile にいる場合
  let path = useResolvedPath("../accounts");
  path.pathname; // "/dashboard/accounts"
  path.search; // ""
  path.hash; // ""
}

シグネチャ

function useResolvedPath(
  to: To,
  {
    relative,
  }: {
    relative?: RelativeRoutingType;
  } = {},
): Path {}

パラメータ

to

解決するパス

options.relative

デフォルトは "route" で、ルーティングがルートツリーに対して相対的になります。相対ルーティングがパスセグメントに対して機能するように、"path" に設定します。

戻り値

pathnamesearch、および hash を含む、解決された Path オブジェクト。