# Knowledge Base "Page Not Found" hardening (KB `$nodeId` route)

## Why this note exists

The Knowledge Base detail route (`ui/src/routes/knowledge/$nodeId.tsx`) could render a
terminal full-pane **"Page Not Found"** screen for node ids it could not resolve. Two
distinct gaps caused it:

1. **No `folder:` branch.** Selecting a KB **folder** node (e.g. the `KNOWLEDGE > All`
   folder) navigates to `/knowledge/folder:knowledge:all`. The route matched none of the
   `domain:` / `group:` / `item:` prefixes, resolved to no graph node, and fell through to
   a bare `<PageNotFound />`. The folder routing (`folder:` → `FolderDetailView`) was
   missing from the template route entirely.
2. **Two hard-404 landmines.** The `!group` and `!node` fall-through branches returned
   `<PageNotFound />`, so any stale bookmark, renamed ontology id, or snapshot drift
   dead-ended the whole content pane.

This train delivers the hardened route that **always renders browsable content** for any
node id. There is **no package bump** — the fix consumes only `@elevasis/ui` exports your
project already has at `@2.49.0+` (`KnowledgeBrowser`, `buildKnowledgeOmTreeData`,
`findKnowledgeTreeNodeByValue`, `KnowledgeTreeNodeData`).

## Applies to

- Every template-derived project whose `ui/src/routes/knowledge/$nodeId.tsx` is still the
  pre-fix version (no `folder:` branch, bare `PageNotFound` returns). If your KB renders
  "Page Not Found" when the `All` (or any) folder node is selected, you are affected.
- No action is required for projects that have already customized this route to handle
  folders and avoid hard 404s — the sync is a `merge-baseline` that **preserves your local
  route edits** (`external-sync-feature-route-baseline`, `sync_lane_severity:
optional-feature-selection`).

## Required actions

`/git-sync` / `/external sync` delivers the hardened route as a baseline merge and surfaces
this note. The route is project-owned baseline content under the route-preservation lane,
so it is **merged, not force-overwritten** — review the merge if you carry local
customizations.

1. **Pull and review.** Run `/git-sync` (or `/external sync`) and review the merge into
   `ui/src/routes/knowledge/$nodeId.tsx`. Accept the two changes: the new `folder:` →
   `FolderDetailView` branch, and the replacement of both `<PageNotFound />` returns with a
   `KnowledgeNodeFallback` (a subtle "not available" `Alert` plus the full
   `KnowledgeBrowser`).
2. **No dependency change.** `@elevasis/ui` does **not** need bumping for this fix; the
   required exports are already published. Do not add a package bump to this sync.
3. **Type-check, then boot.** Run `pnpm -C ui lint` (`tsc --noEmit`), then start the UI.

## Verification

```bash
# 1. The route must no longer return a bare PageNotFound
grep -n "PageNotFound" ui/src/routes/knowledge/$nodeId.tsx
#   Expect: no terminal `return <PageNotFound />` in the content branches
#   (a folder: branch + KnowledgeNodeFallback should be present instead)

# 2. Required @elevasis/ui exports are present at your installed version
grep -n "KnowledgeBrowser\|buildKnowledgeOmTreeData\|findKnowledgeTreeNodeByValue" \
  ui/src/routes/knowledge/$nodeId.tsx

# 3. Template-family coherence
pnpm -C ui lint
```

In the running app, select the `KNOWLEDGE > All` folder node (and any other folder/group
node): the content pane must render browsable Knowledge content, never a full-pane
"Page Not Found".

## Not handled by /git-sync

- `/git-sync` / `/external sync` deliver and merge the route baseline plus this note, but
  they do **not** redeploy your UI. Reaching your live app requires your own UI **redeploy**
  after the sync merge is accepted.
- Local customizations to `ui/src/routes/knowledge/$nodeId.tsx` are preserved by the
  `merge-baseline` lane — if you maintain a forked KB route, reconcile the `folder:` branch
  and the `KnowledgeNodeFallback` into your version by hand rather than discarding your edits.
