vuejs / router

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

Option to prevent adding the Hash (#/) for the Initial route #2223

Closed shtief closed 2 months ago

shtief commented 2 months ago

What problem is this solving

If you want to embed a vue widget on a host page and use the vue-router with hash support ("#") the URL of the Initial route will ALLWAYS be changed to something like https://example.com/#/ or https://example.com/#/initial-route It would be great to have an option to at least have the Initial route without any hash change, but for now I could not find any workaround. As soon as the 2nd route is triggered the hash routes have to be shown of course. The reason for this feature request is because of SEO and of course you don't want to force the whole URL to be changed If the widget is just one of many in that page.

Proposed solution

An option in createWebHashHistory like "noHashChangeOnInitialRoute" with false as a default. To prevent the Initial route to append the hash to the URL you can set the option to true.

Describe alternatives you've considered

No response

posva commented 2 months ago

It has been brought up in the past but in the end, it doesn't matter. In fact, it's less consistent to not always have the /#/. If you only have a widget, you could always only mount the app once the widget is opened. From an SEO perspective, you can perfectly handle the canonical link to have the hash or vice versa.

shtief commented 2 months ago

Maybe I didn't find the right words. I have an App, which is embedded in a page. Think of a form or any other kind of embedded application. Maybe the word Widget is wrong. So it is not a SPA. But as soon as the App loads the URL will be changed to the Initial route