LearnNewsExamplesConnect
Frontmatter
assigneesneo-opus-grace
createdAtNov 16, 2026, 9:55 AM
updatedAtNov 16, 2026, 5:51 PM
githubUrlhttps://github.com/neomjs/neo/issues/21117
authorneo-gemini-julia
commentsCount1
parentIssue20671
subIssues[]
subIssuesCompleted0
subIssuesTotal0
contentTrust
projected
quarantined0
signals[]
blockedBy[x] 21125 Every neo PR fails unit on the claim-responder sibling-repository case
blocking[]
closedAtNov 16, 2026, 5:51 PM

Add opt-in pathname routing in Main and DomEvents for Portal clean URLs

Closed v14.0.0/archive-v14-0-0-chunk-3 enhancementaiarchitecturecoreportal
neo-gemini-julia
neo-gemini-julia commented on Nov 16, 2026, 9:55 AM

Context

Operator Prio-0 search-visibility directive (2026-11-16) under Cornerstone #20671. Directly unblocks neomjs/middleware-v2#21 ("every organic landing is 302-redirected off the URL that ranked") so human search visitors keep clean canonical URLs (/learn/*, /news/*, /examples/*) instead of bouncing 302 -> /#/..., which currently collapses every shared deep link back to /.

The Problem

As verified on neomjs/middleware-v2#21 (#issuecomment-6888508227) and Discussion #20920:

  • src/main/DomEvents.mjs:156, 653 listens strictly to window 'hashchange' and reads location.hash.substring(1).
  • src/Main.mjs:270, 286, 803 (editRoute, setRoute) writes exclusively to window.location.hash.
  • src/ contains zero history.pushState, history.replaceState, or 'popstate' handlers.

If middleware-v2 serves the interactive Portal shell (200 OK) directly at /learn/comparisons/NeoVsReact today, Neo boots at an empty route (/home) and navigation jumps back to #/....

The Architectural Reality

  • Design authority: neomjs/middleware-v2#21 (AC-1–AC-4), ROADMAP.md Cornerstone #4 (#20671), Discussion #20920 (Axis C1), and operator 2026-11-16 Prio-0 directive.
  • Neo.main.DomEvents forwards route transitions to the App Worker as {action: 'hashChange', value: {appName, hash, hashString, windowId}} (src/main/DomEvents.mjs:653-661), where Neo.util.HashHistory (src/util/HashHistory.mjs:98-113) and view controllers consume hashString and hash without reading window.location. Keeping the worker message contract identical while switching DomEvents and Main via an opt-in routerMode config ('hash' default | 'pathname') leaves every standalone app and controller untouched.

The Fix

  1. Add routerMode: 'hash' ('hash' | 'pathname') and routerBasePath: '' configs in src/DefaultConfig.mjs ('hash' remains default across devmode, dist examples, and multi-window apps).
  2. In src/main/DomEvents.mjs and src/Main.mjs: when Neo.config.routerMode === 'pathname':
    • On boot (handleDomContentLoaded / initial route emission), normalize incoming legacy /#/foo URLs via history.replaceState(null, '', normalizePath('/foo')) so shared old #/... bookmarks resolve cleanly, and otherwise derive hashString from window.location.pathname (stripping optional routerBasePath; mapping '/' to '/home' or Portal's root route consistently).
    • Listen to window.addEventListener('popstate', ...) in addition to hashchange so browser Back/Forward dispatches the same App Worker route update.
    • Update Main#setRoute and Main#editRoute in pathname mode to call history.pushState(null, '', targetPathname) and notify DomEvents so HashHistory / ViewportController stay in sync without touching window.location.hash.
  3. Enable opt-in routerMode: 'pathname' for the deployed Portal build configuration (apps/portal/neo-config.json / build hook with companion root-anchored <base href="/dist/production/apps/portal/"> requirement noted for neomjs/pages/buildScripts/enhanceSeo.mjs) so neomjs/middleware-v2#21 can switch human deep routes from 302 to 200 OK.
  4. Add unit tests for DomEvents / Main pathname mode (pushState, popstate, legacy /#/... upgrade via replaceState, and unaltered 'hash' default) plus a Playwright E2E test verifying direct deep-route boot and client navigation with zero # in location.href.

Contract Ledger Matrix

Target Surface Source of Authority Proposed Behavior Fallback / Edge Case Docs Evidence
Neo.config.routerMode / routerBasePath (src/DefaultConfig.mjs) middleware-v2#21 · #20671 Defaults to 'hash'; 'pathname' enables History API routing for Main + DomEvents Unset or 'hash' preserves existing hash behavior byte-for-byte @memberOf! module:Neo JSDoc Unit spec
Neo.main.DomEvents & Neo.Main (setRoute, editRoute, initial route, popstate) src/util/HashHistory.mjs wire shape Emits identical {appName, hash, hashString, windowId} to App Worker from location.pathname; upgrades initial /#/... URLs via replaceState Unknown sub-path or empty pathname resolves safely without throwing; file:// stays 'hash' Method JSDoc Unit + Playwright E2E spec

Decision Record impact: none (Discussion #20920 Axis C1 remains non-blocking post-cut for Docs v2, while this ticket supplies the opt-in engine routing toggle unblocking middleware-v2#21).

Acceptance Criteria

  • src/DefaultConfig.mjs documents routerMode (default 'hash') and routerBasePath (default ''), leaving all existing 'hash' apps and standalone dist/ examples unaffected by default.
  • In 'pathname' mode, initial load at /learn/benefits/Introduction dispatches /learn/benefits/Introduction without rewriting window.location to /#/..., navigation via setRoute/editRoute updates the URL with history.pushState, browser Back/Forward (popstate) updates the App Worker route, and incoming legacy /#/learn/benefits/Introduction upgrades cleanly via history.replaceState.
  • Unit specs and a Playwright test verify both 'hash' default preservation and 'pathname' deep-route boot + multi-step navigation with zero # in window.location.href.
  • Portal clean-URL config wiring and companion neomjs/middleware-v2#21 / neomjs/pages root <base href> cutover steps are documented in the PR.

Out of Scope

  • Prerendered /docs/<ClassName> JSDoc v2 generation (ROADMAP.md post-14.0.0 scope; Discussion #20920).
  • neomjs/middleware-v2 server proxy switch (neomjs/middleware-v2#21 owns server-side 302 → 200 cutover once this engine toggle and root-anchored <base> land).

Avoided Traps

  • Mutating default routerMode to 'pathname' globally: standalone examples loaded via file:// or /dist/production/examples/* would break relative module/resource paths or hit static 404s on reload without middleware rewrites.
  • Serving static HTML from dist/seo/ directly without <script> tags (SsrService.mjs strips MicroLoader.mjs): interactive hydration requires serving the Portal SPA shell at 200 OK alongside this pathname bootstrap.
  • Changing the HashHistory / controller.Base App Worker hashChange contract: keeping DomEvents emitting normalized hashString makes all Portal controllers work without touching app-worker routing code.

Related

Parent: #20671 · neomjs/middleware-v2#21 · Discussion #20920 (Axis C1) · neomjs/pages#58.

unowned-rationale: Prio-0 team deliverable under operator 2026-11-16 directive; curated contributor labels omitted due to core Main/DomEvents architecture touch.

Live latest-open + closed sweep: checked latest 30 open issues (#21114 down to #21006, 59 open total — red band; filed under owning Epic #20671) + open & closed searches (seo OR sitemap OR Search Console OR canonical OR pathname) + neomjs/middleware-v2#21 conversation at 2026-11-16T08:48Z; no existing open or closed Engine ticket implements routerMode: 'pathname' in Main/DomEvents. A2A in-flight claim sweep: list_messages({status: 'all', limit: 15}) at 2026-11-16T08:54Z; zero competing claims on pathname routing. MC sweep: "pathname History routing middleware-v2#21 302 hash redirect DomEvents Main.mjs", 5 results (D#20920 DC_kwDODSospM4BKyBl identified the missing engine C1 pathname prerequisite; no Engine ticket existed yet). Own-assignment sweep: 3 open in neomjs/neo (#21104, #20987, #20671, all bodies read; none implements routerMode: 'pathname'). Structure map: N/A (src/ core browser bootstrap + apps/portal/).

Origin Session ID: 1f283c86-c55b-4aa5-a291-0cbb3786c302 Retrieval Hint: "routerMode pathname History API pushState DomEvents Main.mjs middleware-v2#21 302"