繁体   English   中英

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

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

我现在正在编辑的网站,切换页面的每个链接都有hash符号。 每次我切换并停留在站点的最后一个 position 时,页面都不会刷新。

我在哪里可以找到代码并从 url 中删除 hash。 删除它会使页面每次都刷新吗?

Vue 是一个单页应用程序框架。 这意味着您没有完整的页面加载,而是页面内容在客户端上动态换出。

假设您使用的是vue router ,您可以切换到historyMode ,它不会将#用于 url,而是使用真正的 url。

文档

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.

为了摆脱hash,我们可以使用路由器的历史模式,利用history.pushState API实现URL无页面导航

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

这将为您提供 web 上其他任何地方的“正常”网址。

暂无
暂无

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

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