vuejs / vue-router

🚦 The official router for Vue 2
http://v3.router.vuejs.org/
MIT License
18.99k stars 5.06k forks source link

Route alias and URL encoding issue #3893

Closed zhangyuhan2016 closed 3 months ago

zhangyuhan2016 commented 3 months ago

Version

3.6.5

Reproduction link

codesandbox.io

Steps to reproduce

  1. Define route aliases and route base

    base: "/alias-demo/",
    routes: [
    {
      path: "/search/book",
      alias: ["/alias/book"],
    }
    ]
  2. See browser link

Normal : open URL -> /alias/book?val=%E8%AE%A1%E7%AE%97, browser display link /alias/book?val=%E8%AE%A1%E7%AE%97

Error: open URL -> /alias/book?val=%e8%ae%a1%e7%ae%97, browser display link /alias-demo/alias/book?val=%E8%AE%A1%E7%AE%97

What is expected?

The expected parameter encoding will not affect the route base of the alias

What is actually happening?

The encoding of parameters will affect the route base of aliases


❤️ Thank you for any help you have provided.

vue@2.7.16 vue-router@3.6.5

online demo: https://codesandbox.io/p/devbox/vue-router-question-2xz3gv?file=%2Fsrc%2Frouter%2Findex.ts%3A9%2C7

posva commented 3 months ago

Both open URL are not meant to be handled by this instance of the router since they are missing the base. If you end up having this behavior in production, it means your server is handling routes that do not have a based of alias-demo, which would be a server misconfiguration. Since the router is not meant to handle these case, no specific result can be expected.