docs(labs/router): clarify enter() callback contract#5329
Open
jobrien874 wants to merge 1 commit into
Open
Conversation
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>
🦋 Changeset detectedLatest commit: 1a35f16 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Updates the
enter()callbacks section of@lit-labs/router's README to match the implementation inroutes.ts.The current docs describe
enter()as being able to "optionally reject that route as a match," and the dynamic-routes example comments thatreturn falsecauses the next route to be matched. The implementation does neither: it only checks for strict-equalfalse, and onfalseit bails out ofgoto()silently without falling through to other routes.Changes
entertype signature and parameter shape.falsecancellation contract.goto()Promise still resolves, no event is fired, no error is thrown.enter()surfaces throughgoto()with no internal handling.goto()is called beforereturn false(it's how the new route gets matched, not a side-effect of returning false).rendercallback to interpolateparams[0](was rendering as literal text in the original).Out of scope
The
PathRouteConfigandURLPatternRouteConfiginterfaces shown in the README are also out of date relative toroutes.d.ts(they don't includeenter, and they typeparamsas{[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.tsgoto()andBaseRouteConfiginroutes.d.ts. No code changes.Fixes #5328