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

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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
Ah...I'm sorry about the wrong event name, $stateChangeSuccess is available when using ui-router, not pure AngularJS.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.