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

Router in history mode loses hash when updating query #2868

Closed
denjaland opened this issue Aug 3, 2019 · 5 comments
Closed

Router in history mode loses hash when updating query #2868

denjaland opened this issue Aug 3, 2019 · 5 comments

Comments

@denjaland
Copy link

Version

3.0.6

Reproduction link

https://jsfiddle.net/wjy9Lvgf/

Steps to reproduce

VueJS Router is set up with mode = history.
Consider a route at /security

This page has multiple panes. To decide which pane should be visble, we use the hash to determine this.

Example:
/security#tfa opens the pane where the user can enable/disable two factor authentication
/security#audit opens the pane that has a datatable with the most recent security audits

The query params are mostly used to drive what data is shown.
For instance, the datatable at /security#audit has a table that can be filtered or sorted.
Whenever for instance a table column header is clicked, we set the sort query parameter as follows:

this.$router.push({query: Object.assign({}, this.$route.query, {'sort': sortkey})});

I was under the impression that this method would be intelligent enough ONLY to update the query parameters, and leave the other parts of the route intact (path, params, hash...)

Yet, when we navigate by pushing to the router, ONLY pushing the query, the hash is lost...

So on /security#audit, clicking on the table column 'created', we do
this.$router.push({query: Object.assign({}, this.$route.query, {'sort': 'created'}));

The expected result would be /security?sort=created#audit
-->this would keep the 'audit pane' active, and sort the contents in that table by created date.

However, the result is /security?sort=created

The has should not be lost in that action.

What is expected?

I would not expect the hash to be lost in this case, so the new route would be /security?sort=created#audit

What is actually happening?

The hash is lost; the new route is /security?sort=created


We obviously try and put all these parameters in the route so a user can copy/paste the url and send it to a collleague to link to the correct information.

@posva
Copy link
Member

posva commented Aug 3, 2019

This is intended if you don't provide the query, it gets removed

@posva posva closed this as completed Aug 3, 2019
@denjaland
Copy link
Author

Hi,

I am providing the query. But the hash is being removed...
When you push to the router only parts query, the path doesn't get changed, which is great. but why is the hash being changed?

@posva
Copy link
Member

posva commented Aug 3, 2019 via email

@denjaland
Copy link
Author

But that means I'd have to do that on every single $router.go() call I make. Wouldn't it be more interesting that the router only updates whatever is passed along? I can understand that the hash is lost when you go to a new path or navigate to a named route, but in this case, I'm merely changing query parameters; the path is not being impacted, and I don't believe the hash should either; both the path and hash define on what page / where you are on the page.
The query parameters define the scope of data that is shown.

@posva
Copy link
Member

posva commented Aug 4, 2019 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

No branches or pull requests

2 participants