簡體   English   中英

沒有帶錨標簽的重新加載導航

[英]No reload navigation with anchor tags

我正在嘗試構建一個簡單的 HTML、CSS JS 站點,並且我正在使用錨標記在某些路線之間導航。 我想使用無刷新頁面導航,這意味着它會更改路線並呈現該路線的內容,但在更改路線時不會重新加載。 我怎樣才能做到這一點? 例如:如果你 go 到 nextjs 的文檔,你會注意到它只是改變了路線但沒有重新加載頁面

這可以通過歷史 api 完成

var data = e.target.getAttribute('data-name'),
  url = data + ".html";
  history.pushState(null, null, url);
    
  // here we can fix the current classes
  // and update text with the data variable
  // and make an Ajax request for the .content element
  // finally we can manually update the document’s title

來源: https://css-tricks.com/using-the-html5-history-api/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM