0

I have following problem. On client side I have angular routing, something like that:

...
$locationProvider.html5Mode(true);
    $routeProvider.
        when('/item/:item_id', { reloadOnSearch: false, templateUrl: '/views/main/partials/_item.html', controller: ItemCtrl }).
        otherwise({redirectTo: '/login'}); // Default
...

and some routing on server side on PHP

$req=$_SERVER['REQUEST_URI'];
if(strpos($req,'/login') > -1){
    include __DIR__.'/../views/login/index.php';
} else if(strpos($req,'/item/') > -1) {
    include __DIR__.'/../views/item/index.php';
else {
    include __DIR__.'/../views/login/index.php';
}

all works great except IE, Because when client routing is executed on IE, url is changed from this one

myapp/item/123

to something like this

myapp/#/item/123

and when server side receives this kind of request url after client routing, all data after hash tag are gone and I cannot distinguish which route should be used. Can I remove # from the url, or do something else to make IE and server side live in peace? I failed in attempts to solve it. Thanks

IgorCh
  • 2,641
  • 5
  • 22
  • 29

1 Answers1

2

Your version of IE does not support HTML5 History API. To send the hash you should do some extra work for example do additional ajax request on $routeChangeStart.

Minko Gechev
  • 25,304
  • 9
  • 61
  • 68
  • Event $stateChangeStart doesn't work in this case, but thanks for the hint, I use $routeChangeSuccess or $routeChangeStart, and it helped to solve the problem. Ajax request didn't help, but I made redirect with query parameters and parse these parameters on server side. It is a bit ugly so, maybe someone will advice something better – IgorCh Aug 22 '13 at 08:08
  • Ah...I'm sorry about the wrong event name, `$stateChangeSuccess` is available when using `ui-router`, not pure AngularJS. – Minko Gechev Aug 22 '13 at 10:50