Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigator: support pattern matching #45913

Closed
9 tasks
ciampo opened this issue Nov 18, 2022 · 0 comments · Fixed by #47827
Closed
9 tasks

Navigator: support pattern matching #45913

ciampo opened this issue Nov 18, 2022 · 0 comments · Fixed by #47827
Labels
[Package] Components /packages/components [Type] Enhancement A suggestion for improvement.

Comments

@ciampo
Copy link
Contributor

ciampo commented Nov 18, 2022

Currently the Navigator component can only show a NavigatorScreen component when the current location matches the screen's path exactly.

Following up a request in #45884, in order to enable more advanced patterns we would like to allow the path prop in NavigatorScreen to accept patterns (i.e articles/:articleId), in order to enable pattern matching

Plan of action:

  • Re-architect how the component matches the current location to each NavigatorScreen. This allows Navigator to make sure that only screen in matched in case of potential multiple matches (not too differently from what happens inside the ToolsPanel component)
    • Add an internal instanceId for every NavigatorScreen (automatically generated via dedicated hook)
    • Make it so that every NavigatorScreen element registers itself to the parent NavigatorProvider (indicating its instanceId and its path)
    • With the full list of screens available, NavigationProvider can perform the matching logic (initially, strict equality), and set the instanceId of the matching screen via context
    • Each NavigatorScreen can compare the matching instanceId to their own, and render its contents only if they are matching.
  • Once this re-architecture is in place, we can implement the patter-matching bit:
    • Research how other routing libraries are spec'ing pattern matching syntax
    • Implement pattern matching syntax
    • We should also pass an additional matches object (or similar), where each match is associated to its value (ie. {articleId: 'test-article-id'})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Components /packages/components [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant