vuejs / router

🚦 The official router for Vue.js
https://router.vuejs.org/
MIT License
3.91k stars 1.19k forks source link

Inconsistent results of router.push #1959

Closed mengdu closed 1 year ago

mengdu commented 1 year ago

Reproduction

https://codesandbox.io/s/mutable-sky-22l4gj

Steps to reproduce the bug

router.push('/hello?return_url=' + encodeURIComponent('https://www.my.com'))

and

router.push({
    path: '/hello',
    query: {
      return_url: encodeURIComponent('https://www.my.com')
    }
})

/hello page

<script setup lang="ts">
import { useRouter, useRoute } from 'vue-router'

const route = useRoute()
console.log('hello', route.query)
// hello {return_url: 'https://www.my.com'}
// hello {return_url: 'https%3A%2F%2Fwww.my.com'}
</script>
<template>
  <div>Hello</div>
</template>

Expected behavior

I want got route.query = {return_url: 'https://www.my.com'} but inconsistent results

Actual behavior

Multiple encodeURIComponent

Additional information

No response

posva commented 1 year ago

Do not encode when passing a query object. The router does it for you 🙂