0

I'm setting HTML5 mode on. And thus, links in template are written without hashbang like:

<a ng-href='/link/to/action'>Click here</a>

But problem is, older IE versions need the hashbang urls and I know that angularjs will fallback for IE to hashbang.
But I'm already forming the links according to HTML5. How to fallback my own links to hashbangs?

In other words, I want my links in the template to reflect the mode (HTML5 or hashbang) type and set its href accordingly.

So, for older browsers, I want the link to be like this instead:

<a ng-href='/#/link/to/action'>Click here</a> 
Naughty.Coder
  • 3,922
  • 7
  • 32
  • 41

1 Answers1

1
$locationProvider.html5Mode(false);

Add this to you app.config function, it will disable the html5 mode, and enable hash #

if you need ! also then add this too

$locationProvider.hashPrefix('!');

Ex:

angular.module('yourApp', ['ngCookies', 'ngResource'])
    .config(function($stateProvider, $urlRouterProvider, $locationProvider){
         $locationProvider.html5Mode(false);
         $locationProvider.hashPrefix('!');
    })

EDIT: For checking html5 you can include the modernizer.js library, or use the code samples they provide

Here are some techniques you can use to find a browser supports Html5 or not

http://diveintohtml5.info/detect.html#geolocation

Ex:

if (Modernizr.geolocation) {     
    $locationProvider.html5Mode(true);
} else {
    $locationProvider.html5Mode(false);
}
Vamsi
  • 9,510
  • 6
  • 38
  • 46
  • This is the default behaviour. I'm setting it to ON to enable it, I know. But I want it OFF for older browser versions along with the appropriate type of links in my template that point to the correct mode for every type of browser. – Naughty.Coder Sep 28 '14 at 13:04
  • 1
    Here you have explanation of routing modes in Angular http://stackoverflow.com/questions/16677528/location-switching-between-html5-and-hashbang-mode-link-rewriting – Teq1 Sep 28 '14 at 13:15
  • Check my edit, You can use modernizr.js for detecting html5 browser – Vamsi Sep 28 '14 at 13:19