Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

I have a question for you, is it possible to create a NavLink like structure in React using only HTML5 and JavaScript?

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Yes you can do it using the history API, you can navigate to different pages without refreshing the page

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

Incase of replace the page you can use window.history.replaceState() to replace the current page with the new page.

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading