0

I want the code injected by my chrome extension to update the users pathname without reloading the users app.

Currently i've got a work around

window.history.pushState('', '', '/about')
setTimeout(() => window.history.back(), 10)
setTimeout(() => window.history.forward(), 20)
window.history.pushState('', '', '/about')

Is there a better way of doing this ? maybe i don't understand history state well enough.

Drew Reese
  • 165,259
  • 14
  • 153
  • 181
  • have you seen this post? https://stackoverflow.com/questions/57101831/react-router-how-do-i-update-the-url-without-causing-a-navigation-reload – Fran Na Jaya Sep 22 '21 at 04:30

1 Answers1

1

window.history.replaceState("", "", "/data") this changes the path without reloading the page but you have to handle the page refresh on the index file

and you can append new data by

window.history.replaceState("", "", "/data"); fetch('DataPage.html').then((res) => res.text()).then(res => {document.querySelector("#target").innerHTML = res;})

You have to place a element with id like <div id="target"></div>

VMM
  • 135
  • 1
  • 6