AngularJS: How to clear query parameters in the URL?

后端 未结 16 2606
余生分开走
余生分开走 2020-12-04 14:40

My AngularJS application needs to have access to the user\'s LinkedIn profile. In order to do that I need to redirect the user to a LinkedIn URL which contains a callback re

16条回答
  •  攒了一身酷
    2020-12-04 15:46

    At the time of writing, and as previously mentioned by @Bosh, html5mode must be true in order to be able to set $location.search() and have it be reflected back into the window’s visual URL.

    See https://github.com/angular/angular.js/issues/1521 for more info.

    But if html5mode is true you can easily clear the URL’s query string with:

    $location.search('');
    

    or

    $location.search({});
    

    This will also alter the window’s visual URL.

    (Tested in AngularJS version 1.3.0-rc.1 with html5Mode(true).)

提交回复
热议问题