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

Add optimistic navigation for navigateTo #137

Open
wants to merge 1 commit into
base: fix-scroll-restoration
Choose a base branch
from

Conversation

jho406
Copy link
Collaborator

@jho406 jho406 commented Feb 14, 2025

navigateTo requires a page to exist in the pages slice in order to successfully navigate. You would have to create a page in the store before calling navigateTo. The most common scenario is creating a copy of the current page with new params before navigating. e.g, facet filters.

Its common enough that we add the ability to optimistically navigate. With these changes, you can provide a search hash that will get merged with the existing url query params. The page state is either copied over for history pushs or moved to a new pageKey for history replaces before navigating.

This also encourages folks to use the browser url to reflect application state, just like EmberJS instead of useState. For example:

resolves #135

const {
  navigateTo,
  pageKey,
  search
} = useContext(NavigationContext)

`navigateTo` requires a page to exist in the `pages` slice in order
to successfully navigate. You would have to create a page in the store
before calling `navigateTo`. The most common scenario is creating a copy
of the current page with new params before navigating. e.g, facet filters.

Its common enough that we add the ability to optimistically navigate. With
these changes, you can provide a `search` hash that will get merged with
the existing url query params. The page state is either copied over for
history `push`s or moved to a new pageKey for history `replace`s before
navigating.

This also encourages folks to use the browser url to reflect application
state, just like EmberJS instead of `useState`. For example:

resolves #135

```
const {
  navigateTo,
  pageKey,
  search
} = useContext(NavigationContext)
```
@jho406 jho406 force-pushed the add-optimistic-nav-options branch from 9c2d1a6 to d05d912 Compare February 14, 2025 03:15
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.

1 participant