Diolor
Diolor

Reputation: 13450

Request url when html5Mode(true)

I have enabled $locationProvider.html5Mode(true).

However I have django as backend. On /logout/ I need to ask the url directly to the server as if $locationProvider.html5Mode(false) or simply visiting: example.com/logout/ and not in the fron-end.

Which angular command should I use to "force" ask the /logout/ url from the server?

Upvotes: 0

Views: 423

Answers (1)

LostInComputer
LostInComputer

Reputation: 15420

Edit: Turns out that are are two possible solutions:

1) See Telling Angular Js to ignore a specific route

2) Or use $window.location.

Here is an example:

$scope.onLogoutClicked = function() {
    $window.location = "http://google.com";
}

Difference between $window.location and $location

When should I use $location?

Any time your application needs to react to a change in the current URL or if you want to change the current URL in the browser.

What does it not do? It does not cause a full page reload when the browser URL is changed. To reload the page after changing the URL, use the lower-level API, $window.location.href.

Notes:

  • $window is a wrapper for window so that it can be unit tested.
  • $window.location = "URL" and $window.location.href = "URL" does the same thing

Upvotes: 1

Related Questions