Question

Hi i'm trying replacing

site.com/u#asd with site.com/u

in browser url bar , and i would like to not refresh the page while replacing url

Is this possible?

I tryed:

$location.replace("#asd","");

but it obviously won't work

Était-ce utile?

La solution

  1. You're misusing replace() - it accepts no arguments, and its purpose is said to replace the history record:

    If called, all changes to $location during current $digest will be replacing current history record, instead of adding new one.

  2. You should not use replace in the first place. Instead, call $location.url(), it will not refresh the page (unless you pass true as a second argument).

    From the $location dev guide:

    It does not cause a full page reload when the browser URL is changed.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top