简体   繁体   English

如何从 url 中删除 hash“#”符号?

[英]How to remove the hash "#" symbol from url?

The website that I'm editing right now, every link at switching pages has hash symbol.我现在正在编辑的网站,切换页面的每个链接都有hash符号。 And the page doesn't refresh everytime I switch and sticks on the last position of the site.每次我切换并停留在站点的最后一个 position 时,页面都不会刷新。

Where can I find the code and remove the hash from the url.我在哪里可以找到代码并从 url 中删除 hash。 Does removing it will make the pages refresh everytime?删除它会使页面每次都刷新吗?

Vue is a Single Page Application framework. Vue 是一个单页应用程序框架。 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.假设您使用的是vue router ,您可以切换到historyMode ,它不会将#用于 url,而是使用真正的 url。

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. 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:为了摆脱hash,我们可以使用路由器的历史模式,利用history.pushState API实现URL无页面导航

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

This will get you "normal" urls as seen anywhere else on the web.这将为您提供 web 上其他任何地方的“正常”网址。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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