URLPattern: hash プロパティ
Baseline
2025
Newly available
Since September 2025, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
メモ: この機能はウェブワーカー内で利用可能です。
hash は URLPattern インターフェイスの読み取り専用プロパティで、URL のフラグメント部分と照合するパターンを含む文字列です。
この値は、コンストラクターに渡されたハッシュのパターンの正規化値、 コンストラクターに渡された baseURL からの継承値、任意のハッシュに一致するデフォルト値 ("*") のいずれかです。
値
文字列です。
例
>基本的な使い方
下記の例では URLPattern オブジェクトを作成し、 books/:id をハッシュ部分として指定して、そのプロパティをログ出力します。
このパターンは、 books/ で始まり、任意の文字列識別子で終わるフラグメントと一致します。
js
const pattern = new URLPattern("https://example.org#books/:id");
console.log(pattern.hash); // 'books/:id'
console.log(pattern.test("https://example.org#books/123")); // true
仕様書
| Specification |
|---|
| URL Pattern> # dom-urlpattern-hash> |