@wcstack/router 4.9.0 → 4.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.ja.md CHANGED
@@ -191,7 +191,7 @@ router は、スタンプしたルート本文の終わりにコメントの印
191
191
 
192
192
  output-only メンバーはバインド attach 時に**読まれ**、以後は変更イベントで流れる — 値は「読むもの」であり「待つもの」ではないので、router が最初のルートを解決した後に attach したバインドでも取りこぼしはない。
193
193
 
194
- **発火規範**: commit されたナビゲーションでは、router はまず**全内部値をコミット**し、その後で `data-changed` → `params-changed` → `route-name-changed` → `search-changed` → `path-changed` の順に、値が実際に変化したものだけを発火する(`data` は同一性比較 — guard は遷移ごとに新しいオブジェクトを返す)。どのイベントのリスナーから要素プロパティを読んでも遷移後スナップショットの一貫した値が見える。`path` は最後に発火し「ナビゲーション完了」の信号を兼ねる。前の 4 つはルートの中身を置く**前**に、`path` は置いた後に発火する。だから新しい中身のバインディングは、最初の評価から新しい params と data を読む。guard 拒否されたナビゲーションでは何も更新せず何も発火しない。
194
+ **発火規範**: commit されたナビゲーションでは、router はまず**全内部値をコミット**し、その後で `data-changed` → `params-changed` → `route-name-changed` → `search-changed` → `path-changed` の順に、値が実際に変化したものだけを発火する(`data` は同一性比較 — guard は遷移ごとに新しいオブジェクトを返す)。どのイベントのリスナーから要素プロパティを読んでも遷移後スナップショットの一貫した値が見える。`path` は最後に発火し「ナビゲーション完了」の信号を兼ねる。前の 4 つはルートの中身を置く**前**に、`path` は置いた後に発火する。だから新しい中身のバインディングは、最初の評価から新しい params と data を読む。ページに `<wcs-view-transition>` があると、中身はトランジションの更新コールバックの中で 1 フレーム後に置かれるので、`path` はほかの 4 つの 1 フレーム後に来る: そのフレームの間、state の `path` はまだ離れるページ。そこで別の理由で走るコード — 応答、タイマー — が読み手の今いる場所を要るなら、`path` ではなく `routeName` / `params` / `searchParams` か `location` を読む(そのフレームで扱った 401 は、ログインの後に読み手を離れるページへ戻した)。guard 拒否されたナビゲーションでは何も更新せず何も発火しない。
195
195
 
196
196
  露出オブジェクトは router が所有する **frozen スナップショット**(ナビゲーションごとに新しいオブジェクト、in-place 変異なし)。変異は throw する — 自分の state へコピーして使うこと。唯一の例外が `data` — 所有者は返した guard であり、router はコピーも freeze もしない。
197
197
 
@@ -200,6 +200,11 @@ output-only メンバーはバインド attach 時に**読まれ**、以後は
200
200
  - ページネーション・タブ(戻るボタンで戻りたい)→ `navigateUrl = "?page=2"`
201
201
  - 検索ボックス・絞り込み(履歴を打鍵ごとに汚したくない)→ `replaceUrl = "?q=" + …`(高頻度入力には `<wcs-debounce>` を挟む)
202
202
 
203
+ クエリを URL に持つ検索ページが、何も言わずに間違えることが 2 つある:
204
+
205
+ - **URL が追いつくまでの、読者が打っている文字。** 検索ボックスを URL のクエリ(`searchParams.q`)に束ね、ボックスと `replaceUrl` の間に `<wcs-debounce>` を挟むと、URL は — したがってボックスも — 打鍵より遅れる: 落ち着いた値が URL を書き、router が少し後で commit する。その間、ボックスには古いクエリが書き戻され、打っている指の下で文字が消える。打っている間は打っているものを見せる: ボックス自身の `draft` と `typing` フラグを持ち、フラグは `input` で立て、debounce が落ち着き、その値が URL に入ったら下ろす。URL のクエリを見せるのはフラグが下りているときだけにする(戻る / 進むでもボックスが埋まる)。そして URL は、打たれた値が落ち着いたときにだけ書く: debounce は最初に受けた値でも 1 度落ち着くので、ディープリンク(`/search?q=a&page=2`)ではそれが URL にクエリを書き戻す — `?q=` や、`page` の無い `?q=a` を。
206
+ - **件数の読み上げ。** 文(「12 冊見つかりました」)はリクエストの応答から書く — `<wcs-fetch>` の応答のイベント、`eventToken.value: results` と `$on: { results(state, event) { … } }`([`value` がどの応答か](../fetch/README.ja.md#出力ステートバインド可能な非同期状態))。getter で `value` と今のクエリから組み立てない: 新しいクエリの要求が進んでいる間も `value` は前の応答のままなので、読み上げの領域は、まず新しい条件と前の件数を言った。領域はルートの内容の外に置く([アクセシビリティ契約](#アクセシビリティ契約))。
207
+
203
208
  **マルチ Router**: `params` / `routeName` は各 Router 自身のマッチを反映するが、ページの URL にクエリは 1 つしかない — どの Router 経由で書いてもページ全体のクエリが置き換わる。一方**読み取り面は per-Router**: Router は自分の `basename` 配下のナビゲーションを処理したときだけ `searchParams` を commit するので、その値は「その Router が最後に処理したナビゲーション時点のクエリ」である。
204
209
 
205
210
  #### ナビゲーションターゲットのクエリ文字列
@@ -279,7 +284,7 @@ interface IGuardContext { // 進入先マッチの frozen スナップ
279
284
  - 判定関数が `false` を返すとナビゲーションがキャンセルされ、`guard` 属性のパスへ遷移。空でない文字列を返すとそのパスへ遷移(例: `` return `/login?next=${encodeURIComponent(toPath)}` ``)。`toPath` にクエリは含まれない。リダイレクト先に要るなら第 3 引数の `searchParams` から組み直す(`new URLSearchParams(searchParams)`)
280
285
  - リダイレクトは、キャンセルしたナビゲーションの履歴エントリを**置き換える**。だから「戻る」で守られた URL へ戻る(そしてすぐまたリダイレクトされる)ことはない。リダイレクトはガードの本来の使い方なので、コンソールには何も出さない。ガード同士が送り合うリダイレクトは、続けて 10 回で止め、最後の 1 回を名指すエラーを出す。リダイレクトされたナビゲーションの `navigate()` / `replace()` は `AbortError` で reject する
281
286
  - モジュールは**一度だけ**評価され、関数はナビゲーションのたびに呼ばれる。変わるもの(セッション)は、モジュールの先頭ではなく関数の中で読む
282
- - ガードから `<wcs-state>` の状態は見えない。ページの読み込みでは、最初のルートのガードが `@wcstack/state` の読み込みより先に走ることもある。セッションは、それを保存している場所 — `<wcs-storage>` が保存する `localStorage` のキー(JSON で入っている)— から直接読む。どのタブでも最新の値になる
287
+ - ガードから `<wcs-state>` の状態は見えない。ページの読み込みでは、最初のルートのガードが `@wcstack/state` の読み込みより先に走ることもある。セッションは、それを保存している場所 — `<wcs-storage>` が保存する `localStorage` のキー — から直接読む。どのタブでも最新の値になる。`<wcs-storage>` はオブジェクトと配列を JSON で、文字列はそのまま保存する([JSON 自動シリアライズ](../storage/README.ja.md#json-自動シリアライズ)): 保存したセッションのオブジェクトは `JSON.parse(localStorage.getItem(key))` で読めるが、保存したトークンの文字列ではそれが例外を投げる — 文字列は `getItem` だけで読む
283
288
  - 判定関数は `Promise` を返すことも可能(非同期チェック対応)— 解決するまでルートは commit されない
284
289
  - 第 3 引数に進入先マッチ(`params` / `typedParams` / `searchParams` / `routeName`)が渡る。`toPath` / `fromPath` は basename スライス後のパス
285
290
  - 中に置いた `<wcs-route>` を守る。その中のどこに置いてもよい — 入れ子のルートの前でも後でも、要素の中でも。親のガードは、子のルートへのナビゲーションでも走る
@@ -455,18 +460,18 @@ console.log(router.typedParams.userId); // 123 (number)
455
460
  | 属性 | 説明 |
456
461
  |------|------|
457
462
  | `to` | 遷移先の絶対ルートパスもしくはURL。`/`で始まる場合はルートパス(basename は pathname にのみ付与され、`?クエリ` / `#ハッシュ` はそのまま温存される)。`?` で始まる場合は**クエリのみリンク**:href は「現在 pathname + 指定クエリ」で組み立てられ、ロケーション変更に追従する。それ以外は外部URLとして扱われる。`to` が空の間(`attr.to:` で束ね、まだ書かれていない — router を state より先に読むページ)は、`<a>` に `href` が無く、active にもならない。`to` が来たらそれを書く |
458
- | `match` | `exact`(既定)か `prefix`。`prefix` なら下のパスでも active になる(サイドナビの「商品」が `/products/3` でも)。そのときの `aria-current` は `"true"`(そのパス自身では `"page"`)。下のパスへのリンクにも印が付く: `/products/new` では `prefix` の「商品」と「新しい商品」の両方が active で、`aria-current` は `"true"` と `"page"`。印を 1 つに見せるなら `[aria-current="page"]` でスタイルを書く |
463
+ | `match` | `exact`(既定)か `prefix`。`prefix` なら下のパスでも active になる(サイドナビの「商品」が `/products/3` でも)。そのときの `aria-current` は `"true"`(そのパス自身では `"page"`)。下のパスへのリンクにも印が付く: `/products/new` では `prefix` の「商品」と「新しい商品」の両方が active で、`aria-current` は `"true"` と `"page"`。印を 1 つに見せるなら `[aria-current="page"]` でスタイルを書く。4.10.1 から、クエリのある `prefix` のリンクは、URL のクエリがそのパラメータに加えてほかも持つときも active(`"true"`) |
459
464
 
460
- **アクティブ状態**: 生成された `<a>` はパスが現在のロケーションと一致する場合に `active` クラスと、同じ事実の ARIA 表現である `aria-current="page"` を受け取る(スクリーンリーダーがナビゲーション内の現在地を読み上げられる)。比較は **pathname のみ**で行われ、どちら側のクエリも影響しない(`to="/products"` は `/products?page=2` でも active のまま。クエリのみリンクはそのページに居る間つねに active)。ナビゲーションイベント(`currententrychange`, `wcs:navigate`, `popstate`)で更新される。
465
+ **アクティブ状態**: 生成された `<a>` はパスが現在のロケーションと一致する場合に `active` クラスと、同じ事実の ARIA 表現である `aria-current="page"` を受け取る(スクリーンリーダーがナビゲーション内の現在地を読み上げられる)。クエリの無い `to` は **pathname だけ**で比べ、ページのクエリは影響しない(`to="/products"` は `/products?page=2` でも active のまま)。4.10 から、クエリのある `to` はクエリも比べる: `to="?q=a&page=2"`(「次のページ」)は `/search?q=a` では現在のページではなく、`/search?q=a&page=2` では現在のページ。4.10.1 から、現在のページになるのは URL のクエリが `to` のクエリと等しいとき — 同じパラメータを同じ値で持つとき(順序は問わない)— だけ: `page` を省いた 1 ページ目へのリンク(`to="?q=a"`、新しい検索のきれいな URL)は `/search?q=a&page=2` では現在のページではない。4.10.0 はリンクが名指さないパラメータを構わなかったので、このリンクはどのページでも現在のページだった。重複するキー(`?tag=a&tag=b`)は同じ値の組(順序は問わない)が要り、値はデコードして比べる(`+` と `%20` は同じ)。`match="prefix"` なら、クエリのあるリンクは、URL のクエリがそのパラメータに加えてほかも持つときも `aria-current="true"` で active — `?type=book&sort=-year` の上のファセットのリンク `to="?type=book"` — 下のパスで active なのと同じ(そこでもパラメータは要る)。4.9 まではどちら側のクエリも見なかったので、ページのページ送りのリンクがすべて「現在のページ」になり、スクリーンリーダーは「次のページ、現在のページ」と読んだ。ナビゲーションイベント(`currententrychange`, `wcs:navigate`, `popstate`)で更新される — クエリだけのナビゲーションでも。
461
466
 
462
467
  ```css
463
468
  /* アクティブなリンクのスタイル */
464
469
  a.active { font-weight: bold; color: blue; }
465
470
  ```
466
471
 
467
- **属性の転送**: `<a>` の生成時に、すべての `aria-*` 属性と固定 7 名(`title` / `rel` / `target` / `download` / `hreflang` / `lang` / `dir`)をホストから anchor へコピーする(`lang` / `dir` はスクリーンリーダーの読み上げ言語・方向に直結する)。`to` / `style` / `class` は決して転送しない(ホストは `display:none` であり、`class` は `active` 契約を持つ)。接続後に追従するのは固定 7 名のみで、**動的な `aria-*` 変更は anchor に届かない** — `<wcs-link data-wcs="attr.aria-label: ...">` のような `data-wcs` バインドもコピー後にホストへ書くため届かない。`<wcs-link>` の `aria-*` は静的属性で書くこと。
472
+ **属性の転送**: `<a>` の生成時に、すべての `aria-*` 属性と固定 7 名(`title` / `rel` / `target` / `download` / `hreflang` / `lang` / `dir`)をホストから anchor へコピーする(`lang` / `dir` はスクリーンリーダーの読み上げ言語・方向に直結する)。`to` / `style` / `class` は決して転送しない(ホストは `display:none` であり、`class` は `active` 契約を持つ)。接続後に追従するのは固定 7 名のみで、**`aria-*` の値は anchor を作るときに 1 度だけコピーされ**、その後の変更は anchor に届かない。`data-wcs` のバインド(`<wcs-link data-wcs="attr.aria-label: ...">`)では、値をいつ書くかで決まる: `for:` の行や `if:` の枝の中の `<wcs-link>` は接続より前に束ねられるので、最初の値は anchor を作るときにホストにあってコピーされる — ただしその値の後の変更は届かない。ページのマークアップの `<wcs-link>` は、state が束ねる前に anchor を持つことがあり、そのとき値は届かない。変わらない `aria-*` は静的属性で書き、変わるリンクの名前は中身で与える: ホストの子は anchor へ移されるので、`<wcs-link>` の中の束ねた `<span data-wcs="textContent: …">` は更新され続ける。
468
473
 
469
- **素の `<a>` について**: Navigation API のあるブラウザでは、basename 配下の素の `<a href="/about">` も SPA 遷移になる(router が intercept する)。フォールバックブラウザでは成立しない(SPA 経路は `<wcs-link>` の click ハンドラのみ)ため、推奨は `<wcs-link>` のまま。
474
+ **素の `<a>` について**: Navigation API のあるブラウザでは、basename 配下の素の `<a href="/about">` も SPA 遷移になる(router が intercept する)。フォールバックブラウザでは成立しない(SPA 経路は `<wcs-link>` の click ハンドラのみ)ため、推奨は `<wcs-link>` のまま。4.10 から、素の `<a href="#main">`(フラグメントだけ)はルートの遷移にならず、どちらの経路でも今のページの中で移る — [ページ内リンク](#ページ内リンクスキップリンク)を参照。
470
475
 
471
476
  **読み直しについて**: 4.7 から、ページが求める読み直し — `location.reload()`・`history.go(0)`・`navigation.reload()` — は文書を読み直す。`leaveConfirm` があればブラウザ自身の確認が出る。4.6 までは router が同じ文書の中のルートの遷移として受けたので、「更新があります — 再読み込み」のボタンも Service Worker の更新も効かなかった。basename 配下のほかのナビゲーションは、`location.replace(location.href)` も含めて SPA の遷移のまま。
472
477
 
@@ -575,6 +580,52 @@ router は、プラットフォームが既に正しく行うことについて
575
580
 
576
581
  設計の記録は [docs/a11y-design.md](https://github.com/wcstack/wcstack/blob/main/docs/a11y-design.md) §3 を参照。
577
582
 
583
+ ### ページ内リンク(スキップリンク)
584
+
585
+ 4.10 から、書いたままの `href` がフラグメントだけのリンク — スキップリンクの `<a href="#main">` と、ページ先頭への `href="#"` — は今のページの中で移り、ルートの遷移にはならない:
586
+
587
+ ```html
588
+ <head><base href="/"></head>
589
+ <body>
590
+ <a class="skip-link" href="#main">本文へ移動</a>
591
+ <wcs-router>
592
+ <template>
593
+ <wcs-route path="/search"><main id="main">…</main></wcs-route>
594
+ …
595
+ </template>
596
+ </wcs-router>
597
+ ```
598
+
599
+ - URL は今のパスとクエリ+そのハッシュ(`/search?q=a#main`)になり、どのフラグメントのリンクとも同じく履歴が 1 つ増える(同じフラグメントをもう一度押すと置き換える)。ブラウザが行き先 — その `id` を持つ要素、または `<a name>` — へスクロールし、router がそこへフォーカスを移す。自分でフォーカスを受けない要素には、`focus="heading"` と同じく `tabindex="-1"` を足す。`#` と `#top` は先頭へスクロールし、フォーカスは動かさない。
600
+ - ルートは何も変わらない: guard は走らず、描き直しも無く、`leaveConfirm` も聞かない。2 つの履歴の間の戻る / 進むもフラグメントのナビゲーションで、ルートはそのまま、スクロール位置はブラウザが戻す。
601
+ - 理由: SPA なら必ずある `<base href="/">` の下では、`#main` は `/#main` へ解決される。だから 4.9 までは、`/search?q=a` のスキップリンクで読者はホームのルートへ移った(`<base href="/ja/">` の下では `/ja/` へ)。
602
+ - どちらの経路でも動く。Navigation API があれば、router は `navigate` イベントからリンクを読む(`sourceElement`。今の Chromium・Firefox・Safari は持つ)。無いとき、またはイベントに `sourceElement` が無いときは `window` で click を聞く — ページ自身のリスナーより後なので、ページが取り消したクリックには触らない。
603
+ - 変わらないもの: 修飾キー(Ctrl / ⌘ / Shift / Alt)付きや中ボタンのクリック、`_self` 以外の `target` や `download` を持つリンク、別のページのフラグメントへのリンク(`/faq#x`・`?q=b#x`)、どの router の `basename` の下でもないページ。
604
+
605
+ ### router がページに任せること
606
+
607
+ - **ナビゲーションの後に聞かせたい知らせは、ルートの内容に置かない。** ルートの内容は文と一緒に挿入されるので、その中の `role="status"` / `aria-live` の領域は知らせを持ったまま現れる。スクリーンリーダーが読み上げるのは、すでに知っている領域の変化なので、その知らせは決して読まれない。`<wcs-view-transition>` があると、ルートを置いた後に応答で埋めた領域でさえ、文と一緒に挿入されうる(差し替えが遷移の中で走る)。領域はページに 1 つ、router とその `<wcs-outlet>` の外に置く。ナビゲーションの commit で空にし(router の `path` への `$watch`)、新しいページの文はその後、ページが言うことを持ったときに書く。ページのタイトルなら `announce="title"` が router 自身の領域でそうする。
608
+
609
+ ```html
610
+ <wcs-router data-wcs="path: route"><template>…</template></wcs-router>
611
+ <wcs-outlet></wcs-outlet>
612
+ <p class="visually-hidden" role="status" data-wcs="textContent: status"></p>
613
+ ```
614
+
615
+ ```js
616
+ $eventTokens: ["results"],
617
+ $watch: {
618
+ route() { this.status = ""; }, // ナビゲーションで空にし…
619
+ },
620
+ $on: {
621
+ results(state, event) { // …新しいページは言うことを持ったときに書く
622
+ state.status = `${event.detail.value.length} 冊見つかりました`;
623
+ },
624
+ },
625
+ ```
626
+
627
+ - **ダイアログを閉じた後のフォーカス。** モーダルの `<dialog>` は、閉じると開いた要素へフォーカスを返す。その要素がもう無いとき — ダイアログが、開いたボタンのあった行を消した — フォーカスは `<body>` へ落ち、キーボードやスクリーンリーダーの読者はページの先頭からやり直すことになる。そういう削除の後は自分で移す — リストかその見出しへ: `<h2 tabindex="-1" data-wcs="command.focus: $command.focusList">` と、行が消えた後の `this.$command.focusList.emit()`(ネイティブ要素の `command.` のメソッドは `native-commands` アドオンにあり、full のエントリに入っている)。
628
+
578
629
  ## パス仕様案(Router / Route / Link 共通)
579
630
 
580
631
  ### 用語
@@ -635,11 +686,20 @@ basename が `/ja` なら `/en/orders` へのリンクは `_isOwnPath` を外れ
635
686
  辞退し、ブラウザが本物のナビゲーションを行う。「ただのリンクで切り替わる」のは basename の
636
687
  **おかげ**である。
637
688
 
689
+ この切り替えはページを離れるので、`leaveConfirm` があれば先に聞く — そしてページには、
690
+ 読者が受け入れたかが分からない: click のリスナーは質問より先に走り、断られた切り替えは
691
+ 前の言語のままページに留まる。選んだ言語は、クリックではなく次のページで記録する:
692
+ クリックでは `sessionStorage` に印を付け、次のページの head スクリプトが、URL がその言語を
693
+ 持つときに(`localStorage` へ)確定し、そうでなければ印を捨てる。
694
+
638
695
  副産物が 2 つある。
639
696
 
640
697
  * **ルートパターンからロケールが消える** —— `path="/"`・`path="/about"`。アプリ内リンクも
641
698
  ロケールを持たない(`<wcs-link to="/about">` が basename を前置する)
642
- * **ページ上の URL をすべて絶対にする**こと。`<base>` が相対 URL の基準を変えるため
699
+ * **ページ上の URL をすべて絶対にする**こと。`<base>` が相対 URL の基準を変えるため。
700
+ 4.10 から、フラグメントだけのリンク(`href="#main"`)は例外で、router が
701
+ 今のページに留める([ページ内リンク](#ページ内リンクスキップリンク))。インライン SVG の
702
+ フラグメント参照(`url(#gradient)`・`clip-path`)はリンクではないので、base 基準のまま
643
703
 
644
704
  ロケールを持たない URL や未対応のロケールの修復も、同じ head スクリプトで `location.replace`
645
705
  する。ルートガードには置けない —— guard の redirect 先は静的な `guard="…"` 属性なので、
package/README.md CHANGED
@@ -191,7 +191,7 @@ Commands `navigate(path)` and `replace(path)` (both async) are also declared, so
191
191
 
192
192
  Output-only members are **read** when a binding attaches and streamed through their change events afterwards — the value is read, not awaited, so a binding that attaches after the router already resolved its first route misses nothing.
193
193
 
194
- **Firing contract**: on a committed navigation the router commits *all* internal values first and only then fires events, in the order `data-changed` → `params-changed` → `route-name-changed` → `search-changed` → `path-changed`, each only when its value actually changed (`data` compares by identity — a guard returns a fresh object per navigation). Any listener that reads the element's properties sees the consistent post-navigation snapshot; `path` fires last and doubles as the "navigation finished" signal. The first four fire **before** the route's content is placed and `path` after it, so the bindings inside the new content read the new params and data from their first evaluation. A guard-rejected navigation updates nothing and fires nothing.
194
+ **Firing contract**: on a committed navigation the router commits *all* internal values first and only then fires events, in the order `data-changed` → `params-changed` → `route-name-changed` → `search-changed` → `path-changed`, each only when its value actually changed (`data` compares by identity — a guard returns a fresh object per navigation). Any listener that reads the element's properties sees the consistent post-navigation snapshot; `path` fires last and doubles as the "navigation finished" signal. The first four fire **before** the route's content is placed and `path` after it, so the bindings inside the new content read the new params and data from their first evaluation. With `<wcs-view-transition>` on the page the content is placed in the transition's update callback, a frame later, so `path` comes a frame after the other four: for that frame the state's `path` is still the page being left. Code that runs then for another reason — a response, a timer — and needs where the reader is now reads `routeName` / `params` / `searchParams` or `location`, not `path` (a 401 handled in that frame sent the reader back to the page being left after the login). A guard-rejected navigation updates nothing and fires nothing.
195
195
 
196
196
  The exposed objects are **frozen snapshots** owned by the router: a new object per navigation, never mutated in place. Mutating them throws — copy into your own state instead. `data` is the one exception — it is owned by the guard that returned it, and the router neither copies nor freezes it.
197
197
 
@@ -200,6 +200,11 @@ The exposed objects are **frozen snapshots** owned by the router: a new object p
200
200
  - Pagination, tabs — the back button should step through them: `navigateUrl = "?page=2"`.
201
201
  - Search boxes, filters — the history should not record every keystroke: `replaceUrl = "?q=" + …`, with `<wcs-debounce>` in front of high-frequency input.
202
202
 
203
+ Two things a search page with its query in the URL gets wrong without a word:
204
+
205
+ - **What the reader is typing, while the URL catches up.** With the box bound to the URL's query (`searchParams.q`) and `<wcs-debounce>` between the box and `replaceUrl`, the URL — and so the box — lags the keys: a settle writes the URL, the router commits it a moment later, and in between the box is written back with the older query, under the reader's fingers. Show what is typed while it is being typed: keep the box's own `draft` and a `typing` flag, set on `input` and cleared when the debounce has settled and the URL has what it settled on, and show the URL's query only when the flag is clear (so Back / Forward still fills the box). And write the URL only from a settle of something typed: the debounce settles once for the value it starts with too, and on a deep link (`/search?q=a&page=2`) that settle would write the query back over the URL — `?q=` or `?q=a`, without the `page`.
206
+ - **Announcing the result count.** Write the sentence ("12 books found") from the response of the request — the `<wcs-fetch>`'s response event, `eventToken.value: results` with `$on: { results(state, event) { … } }` ([which response `value` holds](../fetch/README.md#output-state-bindable-async-state)) — not from `value` and the current query in a getter: `value` keeps the previous response while the new query's request is in flight, so the region first said the new query with the previous total. Put the region outside the route content (see [Accessibility contract](#accessibility-contract)).
207
+
203
208
  **Multiple routers**: `params` / `routeName` reflect each router's own match, but the page URL has a single query string — a query written through *any* router replaces the query for the whole page. Reads, however, are per-router: a router commits `searchParams` only when it processes a navigation under its own `basename`, so its value is "the query as of the last navigation this router processed".
204
209
 
205
210
  #### Query strings in navigation targets
@@ -279,7 +284,7 @@ Place as a child of `<wcs-route>` to declaratively define a guard decision funct
279
284
  - If the function returns `false`, navigation is cancelled and the user is redirected to the `guard` path; a non-empty string redirects there instead (e.g. `` return `/login?next=${encodeURIComponent(toPath)}` ``). `toPath` has no query string: rebuild it from the third argument's `searchParams` when the target needs it (`new URLSearchParams(searchParams)`)
280
285
  - A redirect **replaces** the history entry of the cancelled navigation, so Back does not lead to the guarded URL (and straight back to the redirect). It is not logged — it is what the guard is for. Guards that keep redirecting each other are stopped after 10 redirects in a row, with an error naming the last one. A `navigate()` / `replace()` whose navigation is redirected rejects with an `AbortError`
281
286
  - The module is evaluated **once**; the function runs on every navigation. Read anything that changes — a session — inside the function, not at the module's top level
282
- - A guard does not see the `<wcs-state>` tree, and on a page load the landing route's guard can run before `@wcstack/state` has loaded. Read what the session is kept in directly — `localStorage`, under the key a `<wcs-storage>` saves it to (stored as JSON) — which is also current in every tab
287
+ - A guard does not see the `<wcs-state>` tree, and on a page load the landing route's guard can run before `@wcstack/state` has loaded. Read what the session is kept in directly — `localStorage`, under the key a `<wcs-storage>` saves it to — which is also current in every tab. `<wcs-storage>` stores an object or an array as JSON, but a string as it is ([Auto JSON serialization](../storage/README.md#auto-json-serialization)): `JSON.parse(localStorage.getItem(key))` reads a saved session object, and throws on a saved token string — read that with `getItem` alone
283
288
  - The function can return a `Promise` for async checks — the route is not committed until it settles
284
289
  - The third argument carries the match being entered (`params` / `typedParams` / `searchParams` / `routeName`); `toPath` / `fromPath` are basename-sliced paths
285
290
  - It guards the `<wcs-route>` it is inside, wherever it sits there — before or after the nested routes, or inside an element. A parent's guard runs for every navigation into its child routes too
@@ -455,18 +460,18 @@ Link. Converted to an `<a>`, and the route path in the `to` attribute is convert
455
460
  | Attribute | Description |
456
461
  |------|------|
457
462
  | `to` | Destination path or URL. Paths starting with `/` are treated as internal paths (basename is prepended to the pathname; a `?query` / `#hash` suffix is kept as-is). A value starting with `?` is a **query-only** link: the href is assembled as "current pathname + that query" and tracks location changes. Other values are treated as external URLs. While `to` is empty — bound with `attr.to:` and not written yet, as when the router loads before state — the `<a>` has no `href` and is never active; it takes the `to` when it arrives. |
458
- | `match` | `exact` (default) or `prefix`. With `prefix` the link is also active on the paths under it — a side navigation's "Products" on `/products/3` — with `aria-current="true"` there (`"page"` on the path itself). A link to a path under it is marked as well: on `/products/new`, a `prefix` "Products" and a "New product" are both active, with `aria-current="true"` and `"page"`; to show one mark, style `[aria-current="page"]`. |
463
+ | `match` | `exact` (default) or `prefix`. With `prefix` the link is also active on the paths under it — a side navigation's "Products" on `/products/3` — with `aria-current="true"` there (`"page"` on the path itself). A link to a path under it is marked as well: on `/products/new`, a `prefix` "Products" and a "New product" are both active, with `aria-current="true"` and `"page"`; to show one mark, style `[aria-current="page"]`. Since 4.10.1, a `prefix` link with a query is also active (`"true"`) where the URL's query has the link's parameters and more. |
459
464
 
460
- **Active state**: The generated `<a>` receives the `active` class when its path matches the current location, and `aria-current="page"` alongside it — the same fact, expressed in ARIA, so screen readers announce the current page in navigation. The comparison uses the **pathname only** — queries on either side never affect it (so `to="/products"` stays active on `/products?page=2`, and a query-only link is active whenever you are on its page). Tracking is updated on navigation events (`currententrychange`, `wcs:navigate`, `popstate`).
465
+ **Active state**: The generated `<a>` receives the `active` class when its path matches the current location, and `aria-current="page"` alongside it — the same fact, expressed in ARIA, so screen readers announce the current page in navigation. A `to` without a query compares the **pathname only** — the page's query does not matter, so `to="/products"` stays active on `/products?page=2`. Since 4.10, a `to` with a query compares the query too: `to="?q=a&page=2"` ("Next page") is not the current page on `/search?q=a`, and is on `/search?q=a&page=2`. Since 4.10.1, it is the current page only when the URL's query equals `to`'s — the same parameters with the same values, in any order: a page-1 link that leaves `page` out (`to="?q=a"`, the clean URL of a new search) is not the current page on `/search?q=a&page=2`. 4.10.0 allowed parameters the link does not name, so that link was the current page on every page. A repeated key (`?tag=a&tag=b`) needs the same set of values, in any order, and values are compared decoded (`+` and `%20` are the same). With `match="prefix"`, a link with a query is also active, with `aria-current="true"`, where the URL's query has its parameters and more — a facet link `to="?type=book"` on `?type=book&sort=-year` — as it is on the paths under it (with its parameters there too). Up to 4.9 the query was ignored on both sides, so every pagination link on a page was its "current page" and a screen reader read "Next page, current page". Tracking is updated on navigation events (`currententrychange`, `wcs:navigate`, `popstate`), query-only navigations included.
461
466
 
462
467
  ```css
463
468
  /* Style active links */
464
469
  a.active { font-weight: bold; color: blue; }
465
470
  ```
466
471
 
467
- **Attribute forwarding**: when the `<a>` is generated, all `aria-*` attributes plus seven fixed names (`title`, `rel`, `target`, `download`, `hreflang`, `lang`, `dir`) are copied from the host to the anchor (`lang` / `dir` matter to screen readers — they set the announcement language and direction of the link text). `to`, `style`, and `class` are never forwarded (the host is `display:none`, and `class` carries the `active` contract). After connection, only the seven fixed names keep tracking changes; **dynamic `aria-*` changes do not reach the anchor** — this includes `data-wcs` bindings such as `<wcs-link data-wcs="attr.aria-label: ...">`, which write to the host after the copy has happened. Write `aria-*` on `<wcs-link>` as static attributes.
472
+ **Attribute forwarding**: when the `<a>` is generated, all `aria-*` attributes plus seven fixed names (`title`, `rel`, `target`, `download`, `hreflang`, `lang`, `dir`) are copied from the host to the anchor (`lang` / `dir` matter to screen readers — they set the announcement language and direction of the link text). `to`, `style`, and `class` are never forwarded (the host is `display:none`, and `class` carries the `active` contract). After connection, only the seven fixed names keep tracking changes; **an `aria-*` value is copied once, when the anchor is created**, and a later change never reaches the anchor. With a `data-wcs` binding (`<wcs-link data-wcs="attr.aria-label: ...">`) it depends on when the value is written: a `<wcs-link>` in a `for:` row or an `if:` branch is bound before it is connected, so its first value is on the host when the anchor is created and is copied — but a later change of that value is not; a `<wcs-link>` in the page markup may have its anchor before state binds it, and then the value never arrives. Write `aria-*` that does not change as static attributes, and give a link a name that changes through its content: the host's children are moved into the anchor, so a bound `<span data-wcs="textContent: …">` inside `<wcs-link>` keeps updating.
468
473
 
469
- **Plain `<a>` note**: in browsers with the Navigation API, a plain `<a href="/about">` under the basename also becomes an SPA navigation (the router intercepts it). This does not hold in fallback browsers, where only `<wcs-link>`'s click handler provides SPA navigation — so `<wcs-link>` remains the recommendation.
474
+ **Plain `<a>` note**: in browsers with the Navigation API, a plain `<a href="/about">` under the basename also becomes an SPA navigation (the router intercepts it). This does not hold in fallback browsers, where only `<wcs-link>`'s click handler provides SPA navigation — so `<wcs-link>` remains the recommendation. Since 4.10, a plain `<a href="#main">` (a bare fragment) is never a route change: it moves within the current page, on both paths — see [In-page links](#in-page-links-skip-links).
470
475
 
471
476
  **Reload note**: since 4.7, a reload the page asks for — `location.reload()`, `history.go(0)`, `navigation.reload()` — reloads the document, and with `leaveConfirm` set it gets the browser's own prompt. Up to 4.6 the router took it as a route change in the same document, so an "update available — reload" button or a service worker's update flow did nothing. Every other navigation under the basename, `location.replace(location.href)` included, stays an SPA navigation.
472
477
 
@@ -575,6 +580,52 @@ These are the specification defaults; writing them out records the delegation as
575
580
 
576
581
  See [docs/a11y-design.md](https://github.com/wcstack/wcstack/blob/main/docs/a11y-design.md) §3 for the design record.
577
582
 
583
+ ### In-page links (skip links)
584
+
585
+ Since 4.10, a link whose `href` as written is a bare fragment — a skip link, `<a href="#main">`, and `href="#"` for the top of the page — moves within the current page, and is never a route change:
586
+
587
+ ```html
588
+ <head><base href="/"></head>
589
+ <body>
590
+ <a class="skip-link" href="#main">Skip to content</a>
591
+ <wcs-router>
592
+ <template>
593
+ <wcs-route path="/search"><main id="main">…</main></wcs-route>
594
+ …
595
+ </template>
596
+ </wcs-router>
597
+ ```
598
+
599
+ - The URL becomes the current path and query plus that hash (`/search?q=a#main`), with a history entry as any fragment link makes (the same fragment again replaces it). The browser scrolls to the target — the element with that `id`, or an `<a name>` — and the router moves focus to it, adding `tabindex="-1"` when it does not take focus itself, as `focus="heading"` does. `#` and `#top` scroll to the top and leave focus where it is.
600
+ - Nothing about the route changes: no guard runs, nothing is rendered again, `leaveConfirm` does not ask. Back / Forward between the two entries are fragment navigations as well — the route stays and the browser restores the scroll position.
601
+ - Why: under `<base href="/">`, which every SPA has, `#main` resolves to `/#main`. Up to 4.9 a skip link on `/search?q=a` therefore took the reader to the home route (under `<base href="/ja/">`, to `/ja/`).
602
+ - It works on both paths. With the Navigation API the router reads the link from the `navigate` event (`sourceElement`, which current Chromium, Firefox and Safari give); without it, or where the event has no `sourceElement`, it listens for the click on `window`, after the page's own listeners — a click the page cancelled is left alone.
603
+ - Unchanged: a click with a modifier (Ctrl / ⌘ / Shift / Alt) or the middle button, a link with a `target` other than `_self` or with `download`, a link to another page's fragment (`/faq#x`, `?q=b#x`), and a page outside every router's `basename`.
604
+
605
+ ### What the router leaves to the page
606
+
607
+ - **A message meant to be heard after a navigation does not belong in the route content.** The route content is inserted together with its text, so a `role="status"` / `aria-live` region in it arrives with its message already there, and a screen reader announces changes to a region it already knows: the message is never read. With `<wcs-view-transition>`, even a region filled from a response after the route was placed can be inserted with its text (the swap runs inside the transition). Keep one region for the page, outside the router and its `<wcs-outlet>`; empty it when a navigation commits (a `$watch` on the router's `path`), and write the new page's sentence after that, when the page has it. For the page title, `announce="title"` does this already, in the router's own region.
608
+
609
+ ```html
610
+ <wcs-router data-wcs="path: route"><template>…</template></wcs-router>
611
+ <wcs-outlet></wcs-outlet>
612
+ <p class="visually-hidden" role="status" data-wcs="textContent: status"></p>
613
+ ```
614
+
615
+ ```js
616
+ $eventTokens: ["results"],
617
+ $watch: {
618
+ route() { this.status = ""; }, // a navigation empties it…
619
+ },
620
+ $on: {
621
+ results(state, event) { // …and the new page writes when it has something to say
622
+ state.status = `${event.detail.value.length} books found`;
623
+ },
624
+ },
625
+ ```
626
+
627
+ - **Focus after a dialog closes.** A modal `<dialog>` gives focus back to the element that opened it when it closes. When that element is gone — the dialog deleted the row whose button opened it — focus falls to `<body>`, and a keyboard or screen-reader user starts again from the top of the page. Move it yourself after such a removal, to the list or its heading: `<h2 tabindex="-1" data-wcs="command.focus: $command.focusList">` and `this.$command.focusList.emit()` once the row is gone (a native element's `command.` methods come with the `native-commands` add-on, in the full entries).
628
+
578
629
  ## Path Specification (Router / Route / Link)
579
630
 
580
631
  ### Terminology
@@ -638,12 +689,22 @@ With basename `/ja`, a link to `/en/orders` falls outside `_isOwnPath`, the
638
689
  router declines to intercept, and the browser performs a real navigation. The
639
690
  "just a link" language switch works *because* of the basename.
640
691
 
692
+ It also leaves the page, so with `leaveConfirm` set it asks first — and the page
693
+ cannot tell whether the reader accepted: a click listener runs before the
694
+ question, and a declined switch stays on the page in the old language. Record
695
+ the chosen language on the next page, not on the click: mark it in
696
+ `sessionStorage` on click, and let the next page's head script commit it (to
697
+ `localStorage`) when the URL carries that language, and drop the mark otherwise.
698
+
641
699
  Two consequences worth having:
642
700
 
643
701
  * **Route patterns carry no locale** — `path="/"`, `path="/about"`. In-app links
644
702
  stay locale-free too (`<wcs-link to="/about">` prepends the basename).
645
703
  * **Every URL on the page must be absolute**, since `<base>` now changes what
646
- relative URLs resolve against.
704
+ relative URLs resolve against. A link to a bare fragment (`href="#main"`) is
705
+ the exception since 4.10: the router keeps it on the current page
706
+ ([In-page links](#in-page-links-skip-links)). Inline-SVG fragment references
707
+ (`url(#gradient)`, `clip-path`) are not links, and still resolve against the base.
647
708
 
648
709
  Repairing a URL that carries no locale, or an unknown one, belongs in that same
649
710
  head script (`location.replace`) rather than a route guard: a guard's redirect