vuejs / router

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

Router resolve does not encode path #2021

Closed Achneoder closed 10 months ago

Achneoder commented 10 months ago

Reproduction

https://github.com/vuejs/router/compare/main...Achneoder:router:test_path_encoding

Steps to reproduce the bug

  1. Checkout repository and branch test_path_encoding
  2. pnpm i
  3. pnpm test

Expected behavior

The test succeeds.

Actual behavior

The test fails.

Additional information

According to the documentation, router.resolve should return a RouteLocation with encoded fullPath (same for path).

I don't know if the current behavior is intended, so that the provided path and/or params already have to be encoded, but that might be inconsistent since the query params will be encoded properly.

posva commented 10 months ago

This is working as intended: encoding is done in params and query. Passing a path string lets the browser encode it (https://router.vuejs.org/guide/migration/#-route-properties-Encoding). This is why it's recommended to use named routes with params if params can contain encoded characters 🙂