Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

IE8, html5Mode route to root error & fix #6832

Closed
LorDOniX opened this issue Mar 25, 2014 · 8 comments
Closed

IE8, html5Mode route to root error & fix #6832

LorDOniX opened this issue Mar 25, 2014 · 8 comments

Comments

@LorDOniX
Copy link

Hi,
I was testing route with html5Mode(true) in IE8. Angular for IE8 sets html5Mode to false and uses hashbang, instead of HTML5 history API.
But problem is when you route to the root url of your site, nothing is shown.

router:
$routeProvider.
when('/', {
templateUrl: '/partials/phone-list.html',
controller: 'PhoneListCtrl'
}).
otherwise({redirectTo: '/'});

$locationProvider.html5Mode(true);
$locationProvider.hashPrefix('!');

I found out the solution for this problem:

function LocationHashbangUrl(appBase, hashPrefix) {

and inside function:

this.$$parse = function(url) {
if (!url) {
url = appBase;
}

I've added three lines which contains check for empty url - when you route to the root of your website.
Can be this fix included to the next 1.2.x version of AngularJS ?

@caitp
Copy link
Contributor

caitp commented Mar 25, 2014

Can be this fix included to the next 2.1.x version of AngularJS ?

Can you send a pull request so it can be reviewed? Thanks.

@LorDOniX
Copy link
Author

Thank you for your replay, I will create it a pull request.

@IgorMinar
Copy link
Contributor

If I understand it correctly you are saying that if your app is at http://myapp.com and you open http://myapp.com in IE8 then nothing happens. Is that right?

@IgorMinar
Copy link
Contributor

I tested this scenario with IE8 on http://docs.angularjs.org/ and it works as expected (the app itself is broken mainly because of CSS issues, but angular will redirect to http://docs.angularjs.org/!#/api)

@LorDOniX
Copy link
Author

Hi, yes, steps to reproduce:

  1. router in angular js has to be set to html5 mode, prefix with !
  2. navigation to the root of your site works in all browsers except IE8 and I think IE9
    If you navigate to the root http://myapp.com (see my fix) so inside this function, router throws an error for - empty string and operation indexOf. If you add my fix, function change url from undefined to current url and this problem is fixed.

@LorDOniX
Copy link
Author

I've also send pull request - https://github.com/angular/angular.js/pull/6834/files

@IgorMinar
Copy link
Contributor

I've seen the PR. It doesn't have any tests so I can't tell if it does anything.

My point is that the case you described works just fine for docs.angularjs.org which uses the same setup. So I'm thinking that there is another variable that you haven't mentioned.

@ashleygwilliams ashleygwilliams added this to the Backlog milestone Mar 27, 2014
@LorDOniX
Copy link
Author

Yes, you're right.
In the source code, I've found html5 mode set to true, but I did not find anything about route (something like this):

$routeProvider
.when("/", {
templateUrl: "/templates/main.html",
controller: "MainCtrl"
})
.when("/somepage", {
templateUrl: "/templates/somepage.html",
controller: "SomeCtrl"
})
.otherwise({
redirectTo: '/'
});
Also docs.angularjs.org are redirected to the /api, not to the root of the website.
So I think, this could be the different from my problem.

@caitp caitp closed this as completed in 3f04770 Apr 17, 2014
caitp pushed a commit to caitp/angular.js that referenced this issue Apr 17, 2014
…Mode

Previously, LocationHashbangInHtml5Url, which is used when html5Mode is enabled
in browsers which do not support the history API (IE8/9), would behave very
inconsistently WRT relative URLs always being resolved relative to the app root
url.

This fix enables these legacy browsers to behave like history enabled browsers,
by processing href attributes in order to resolve urls correctly.

Closes angular#6162
Closes angular#6421
Closes angular#6899
Closes angular#6832
Closes angular#6834
caitp pushed a commit that referenced this issue Apr 18, 2014
…Mode

Previously, LocationHashbangInHtml5Url, which is used when html5Mode is enabled
in browsers which do not support the history API (IE8/9), would behave very
inconsistently WRT relative URLs always being resolved relative to the app root
url.

This fix enables these legacy browsers to behave like history enabled browsers,
by processing href attributes in order to resolve urls correctly.

Closes #6162
Closes #6421
Closes #6899
Closes #6832
Closes #6834
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants