简体   繁体   中英

How to remove the hash "#" symbol from url?

The website that I'm editing right now, every link at switching pages has hash symbol. And the page doesn't refresh everytime I switch and sticks on the last position of the site.

Where can I find the code and remove the hash from the url. Does removing it will make the pages refresh everytime?

Vue is a Single Page Application framework. That means you don't have full page loads, instead page content is swapped out dynamically on the client.

Assuming you're using vue router , you can switch to historyMode which won't use # for urls and instead real urls.

From the docs :

The default mode for vue-router is hash mode - it uses the URL hash to simulate a full URL so that the page won't be reloaded when the URL changes.

To get rid of the hash, we can use the router's history mode, which leverages the history.pushState API to achieve URL navigation without a page reload:

const router = new VueRouter({ mode: 'history', routes: [...] })

This will get you "normal" urls as seen anywhere else on the web.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM