feat: optimize method to determine whether the two path are the same in ensureUrl methods#3477
Conversation
…in ensureUrl methods
…e equal considering the order of attributes
posva
left a comment
There was a problem hiding this comment.
Can you add e2e tests for both hash and html5 history as well?
| const aKeys = Object.keys(a).sort() | ||
| const bKeys = Object.keys(b).sort() | ||
| const aKeys = Object.keys(a) | ||
| const bKeys = Object.keys(b) |
There was a problem hiding this comment.
if that not be removed, they are the same object as below:
var a = {a:1,b:2}; var b = {b:2,a:1};
Object.keys method will keep the order of attributes in an object as the attributes were added.
if that not be removed, "https://vesaas.com/?a=1&b=2" and "https://vesaas.com/?b=2&a=1" will be thought the same route.
ensureURL (push?: boolean) {
const location = getHash()
const plainRoute = createPlainRoute(location)
if (!isSameRoute(plainRoute, this.current)) {
const current = this.current.fullPath
push ? pushHash(current) : replaceHash(current)
}
}
the "ensureURL " method will not go into 'if ' block in this scene.
| } | ||
| } | ||
| /** just create a route without any added process */ | ||
| export function createPlainRoute (url: string): Route { |
There was a problem hiding this comment.
Ideally, this function (and its tests) should be removed since we just need to call normalizeLocation() on the url and compare it with this.current
There was a problem hiding this comment.
but how to compare with this current ,this.current is a Route object.I thought if it turn to a Route object , the logic can be keep smooth and complete.
I try my best to do it. |
|
upvote 👍 |
|
I've just tried the fix by @wxwzl but as far as I can determine this isn't fixing the issue that query params are sorted on init. |
Fix #3447 , optimize method to determine whether the two path are the same in ensureUrl methods