Using `history.replace` with Angular 1.x

I need help with help history.replaceState

in an Angular 1.x app.

My chrome extension is interacting with some elses app, and I want to load a Url in that app with an additional query parameter that my extension can extend and then use history.replaceState

to remove from the url.

  • Step 1: open www.otherapp.com?extensionToken=MhtkWGUyS#/settings

  • Step 2: read xtensionToken=MhtkWGUyS

  • Step 3: replace / remove token from replaceState

    beforewww.otherapp.com#/settings

The problem is Angular 1.x can't use history.replaceState on its own: https://github.com/angular/angular.js/issues/3789 p>

Angular seems to be reversing my update back to the original url, or cross-url altogether. Anyone have any experience history.replaceState

with an Angular app?

One solution I was thinking about was using Angular s $location

to change state, but I don't know how to access $location

outside of Angular scope. Does anyone know how I can access this?

The tricky part of generating a link to $location

is that my code will work with many different applications with their own unique Angular elements ng-

, and I don't know what those elements are on the page. I can assume most of them have Angular in window.angular

, but I cannot easily assume that there will be an Angular app element for every page.

+3


source to share





All Articles