簡體   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