Skip to content

docs(labs/router): clarify enter() callback contract#5329

Open
jobrien874 wants to merge 1 commit into
lit:mainfrom
jobrien874:docs/labs-router-enter-callback
Open

docs(labs/router): clarify enter() callback contract#5329
jobrien874 wants to merge 1 commit into
lit:mainfrom
jobrien874:docs/labs-router-enter-callback

Conversation

@jobrien874

Copy link
Copy Markdown

Description

Updates the enter() callbacks section of @lit-labs/router's README to match the implementation in routes.ts.

The current docs describe enter() as being able to "optionally reject that route as a match," and the dynamic-routes example comments that return false causes the next route to be matched. The implementation does neither: it only checks for strict-equal false, and on false it bails out of goto() silently without falling through to other routes.

Changes

  • Add the enter type signature and parameter shape.
  • Document the strict-false cancellation contract.
  • Document that cancellation is silent — the goto() Promise still resolves, no event is fired, no error is thrown.
  • Document error propagation: a thrown or rejected enter() surfaces through goto() with no internal handling.
  • Reword the dynamic-routes example comment so it accurately describes why goto() is called before return false (it's how the new route gets matched, not a side-effect of returning false).
  • Fix the example's render callback to interpolate params[0] (was rendering as literal text in the original).

Out of scope

The PathRouteConfig and URLPatternRouteConfig interfaces shown in the README are also out of date relative to routes.d.ts (they don't include enter, and they type params as {[key: string]: string} instead of {[key: string]: string | undefined}). Happy to follow up with a separate PR if useful.

Verification

Behavior described matches packages/labs/router/src/routes.ts goto() and BaseRouteConfig in routes.d.ts. No code changes.

Fixes #5328

Document the actual behavior of the enter() callback as implemented in
routes.ts:

- Add the type signature and parameter shape.
- Document that only strict-equal false cancels the navigation.
- Document that cancellation is silent (no event, no error, the goto()
  Promise still resolves).
- Note that returning false does not fall through to the next matching
  route.
- Document error propagation through goto().
- Clarify the dynamic-routes example to explain why goto() is called
  before returning false.

Signed-off-by: Josh O'Brien <jobrien874@gmail.com>
@jobrien874 jobrien874 requested a review from kevinpschaaf as a code owner May 8, 2026 18:19
@changeset-bot

changeset-bot Bot commented May 8, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 1a35f16

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@lit-labs/router Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[labs/router] README documentation for enter() callback doesn't match implementation

1 participant