Vicary
Vicary

Reputation: 1064

How to disable html5mode on otherwise?

I want to switch off $locationProvider.html5Mode() when the path goes out of my routes. (a.k.a. /pages).

The otherwise route currently consumes my links to other pages and only updates the ng-view with a blank template, I want the whole page reloads to target page instead.

Here is my code.

app.config(function($locationProvider, $routeProvider) {
  $routeProvider.when('/page/:url', {
    controller: 'PageCtrl',
    templateUrl: 'page-template.html'
  })
  .otherwise({
    redirectTo: function(params, path) {
      window.location = path;
    }
  });

  $locationProvider.html5Mode(true);
});

Upvotes: 1

Views: 1081

Answers (1)

Vicary
Vicary

Reputation: 1064

I have found a work around to this, by adding all "reloading" links with a target="_self".

Below is a portion of RTFM.

Html link rewriting

In cases like the following, links are not rewritten; instead, the browser will perform a full page reload to the original link.

  • Links that contain target element
    Example: <a href="/ext/link?a=b" target="_self">link</a>
  • Absolute links that go to a different domain
    Example: <a href="http://angularjs.org/">link</a>
  • Links starting with '/' that lead to a different base path
    Example: <a href="/not-my-base/link/">link</a>

Upvotes: 2

Related Questions