I need help using history.replaceState
on an Angular 1.x app.
My Chrome extension interacts with someone else’s app, and I want to load a Url in that app with an extra query parameter that my extension can read, and then use history.replaceState
to remove from the url.
www.otherapp.com?extensionToken=MhtkWGUyS#/settings
xtensionToken=MhtkWGUyS
replaceState
to www.otherapp.com#/settings
The trouble is that Angular 1.x doesn’t like history.replaceState to be used on its own: https://github.com/angular/angular.js/issues/3789
Angular seems to revert my update back to the original Url, or scramble the Url altogether. Does anyone have experience using history.replaceState
with an Angular app?
One solution I thought of was to use Angular’s $location
to make the state-change, but I’m don’t know how to access $location
outside of the Angular scope. Does anyone know how I might access that?
The tricky part of generating a reference to $location
is that my code will run with many different apps, with their own unique angular ng-
elements, and I don’t know what those elements are on the page. I can assume that most have Angular at window.angular
, but I can’t easily assume what the Angular app element will be for each page.