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

feat(useRouteQuery, useRouteHash): add preserveHash/preserveQuery option #2107

Closed
wants to merge 3 commits into from

Conversation

jeongtae
Copy link

Description

In the current version, updating the query will lose the hash and vice versa.

const query = useRouteQuery('q')
const hash = useRouteHash()
query = 'foo' // http://some.url/?q=foo
hash.value = 'bar' // http://some.url/#bar  *query is removed*

This PR enables the following approach:

const hashPreservesQuery = useRouteHash(undefined, { preserveQuery: true })
query.value = 'foo' // http://some.url/?q=foo
hashPreservesQuery.value = 'bar' // http://some.url/?q=foo#bar

Additional context

vue-router removes a query(or hash) unless explicitly specified. The maintainer said it is intentional behavior. (vuejs/vue-router#2868)
But since these hooks abstract vue-router push/replace, I thought it should be able to preserve a query/hash via options.

I'm not good at English. Any comments about English grammar on JSDocs are welcome.

Thanks for providing nice hooks.


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@stale
Copy link

stale bot commented Oct 20, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Oct 20, 2022
@stale stale bot closed this Oct 27, 2022
@mercmobily
Copy link

Is this not going to be merged?

@jeongtae
Copy link
Author

@mercmobily

This was addressed in PR #2350 via a different method.

And it was deployed in v9.4.0, so if you're experiencing issues like the one in the text, I recommend upgrading your library version.

@mercmobily
Copy link

mercmobily commented Mar 17, 2024 via email

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.

None yet

2 participants