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.push with query {id: undefined} can not work when prev query is {aaa: 'xxx'} #3341

Closed
laomu1988 opened this issue Oct 14, 2020 · 1 comment
Labels

Comments

@laomu1988
Copy link

Version

3.4.6

Reproduction link

https://codepen.io/laomu1988/pen/QWEjezL?editors=1011

Steps to reproduce

click jump button

What is expected?

router changed

What is actually happening?

router not change and the console has error info.

@laomu1988
Copy link
Author

the function isObjectEqual at https://github.com/vuejs/vue-router/blob/dev/src/util/route.js

function isObjectEqual (a = {}, b = {}): boolean {
  // handle null value #1566
  if (!a || !b) return a === b
  const aKeys = Object.keys(a)
  const bKeys = Object.keys(b)
  if (aKeys.length !== bKeys.length)  {
    return false
  }

  return aKeys.every(key => {
      // ---------------  add lines   ---------------
      if (!bKeys.includes(key)) {
           return false;
      }
      //  -------------end ---------------

    const aVal = a[key]
    const bVal = b[key]
    // query values can be null and undefined
    if (aVal == null || bVal == null) return aVal === bVal

    // check nested equality
    if (typeof aVal === 'object' && typeof bVal === 'object') {
      return isObjectEqual(aVal, bVal)
    }
    return String(aVal) === String(bVal)
  })
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants