簡體   English   中英

是否可以僅使用 HTML5 和 JavaScript 在 React 中創建類似 NavLink 的結構?

[英]Is it possible to create a NavLink like structure in React using only HTML5 and JavaScript?

我有一個問題要問你,是否可以僅使用 HTML5 和 JavaScript 在 React 中創建類似 NavLink 的結構?

For example, if we have a homepage.html and a content.html file and I want to go to content.html when an "a" element is clicked, how can I do this without refreshing the page?

是的,您可以使用歷史記錄 API 來做到這一點,您可以導航到不同的頁面而無需刷新頁面

window.history.pushState('page 2, "page 2 title", "page2.html")

如果要替換頁面,您可以使用window.history.replaceState()將當前頁面替換為新頁面。

參考:- https://developer.mozilla.org/en-US/docs/Web/API/History_API/Working_with_the_History_API

暫無
暫無

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

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