Skip to content

$locationProvider.html5Mode(true) broken #2032

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kikar opened this issue Jun 12, 2015 · 16 comments
Closed

$locationProvider.html5Mode(true) broken #2032

kikar opened this issue Jun 12, 2015 · 16 comments
Labels

Comments

@kikar
Copy link

kikar commented Jun 12, 2015

I used Express with no parameters to generate a quick server that will serve these 2 files:

angular.module('myApp', ['ui.router'])
.config(['$locationProvider', function($locationProvider) {

    $stateProvider
    .state('home', {
        url: '/',
        template: '<h1>Home</h1>'
    });

    $locationProvider.html5Mode(true);
}]);
<!DOCTYPE html>
<html ng-app="myApp" ng-strict-di>
<head>
    <title>Lunr Test</title>
    <base href="./">
</head>
<body>
    <nav>
        <ul>
            <li><a ui-sref="home">Home</a></li>
        </ul>
    </nav>

    <div ui-view></div>

    <script src="lib/angular.min.1.3.js"></script>
    <script src="lib/angular-ui-router.min.js"></script>

    <script src="app.js"></script>
</body>
</html>

Using UIRouter 0.2.14 and AngularJS 1.3.16 and I get this error twice in console:

TypeError: Cannot read property 'replace' of undefined
    at Gb (angular.min.1.3.js:94)
    at Re.$get (angular.min.1.3.js:100)
    at Object.e [as invoke] (angular.min.1.3.js:36)
    at angular.min.1.3.js:38
    at d (angular.min.1.3.js:36)
    at Object.e [as invoke] (angular.min.1.3.js:36)
    at angular.min.1.3.js:38
    at d (angular.min.1.3.js:36)
    at Object.e [as invoke] (angular.min.1.3.js:36)
    at angular.min.1.3.js:38

Works normally when setting html5Mode to false, or when I comment that line.

@nateabele
Copy link
Contributor

Seems like it should work. Pretty surprising since it's such a commonly-used feature.

Can anybody else confirm this?

@eddiemonge
Copy link
Contributor

I can confirm this exists.

@eddiemonge eddiemonge added the bug label Jun 26, 2015
@jazzblue
Copy link

jazzblue commented Jul 8, 2015

It is not only ui-router issue, I get it just by doing $locationProvider.html5Mode(true) without any ui-router.

@eddiemonge
Copy link
Contributor

So if you take out all traces of ui-router its still happening?

@jazzblue
Copy link

jazzblue commented Jul 8, 2015

Yes, I do not use ui-router at all.

@jazzblue
Copy link

jazzblue commented Jul 8, 2015

I have just tried this workaround:
#116
(ggoodman commented on May 6, 2013)

...and it seems to be working. Still checking...

@eddiemonge
Copy link
Contributor

I am inclined to close this issue then. @kikar if you take out ui-router do you still have the bug?

@kikar
Copy link
Author

kikar commented Jul 21, 2015

Seems to be an Angular problem. Don't have bug anymore

@kikar kikar closed this as completed Jul 21, 2015
@moander
Copy link

moander commented Nov 13, 2015

Still broken.

Quick fix:

  app.run(function ($browser) {
    $browser.baseHref = function () { return "/" };
  });

@pavel06081991
Copy link

Yeah, still have this problem

@connor11528
Copy link

@moander's solution works but all you have to do is change <base href="./"> to <base href="/">

More info on this SO post: http://stackoverflow.com/questions/17768814/ngroute-set-base-url-for-all-routes

@zhuhongyin
Copy link

thanks moander's solution ,fixed by
app.run(function ($browser) {
$browser.baseHref = function () { return "/" };
});

@sukrosono
Copy link

Thanks @cleechtech and @moander , you save my day. I prefer using that solution via template

@Parziphal
Copy link

@cleechtech is right. All you have to make sure is that the value for href in your <base> tag has a leading slash, or if it's root, it should be only a slash. Examples:

Wrong:
<base href="foo/">
<base href="./foo/">

Right:
<base href="/foo/">
<base href="/">

@aipirvu
Copy link

aipirvu commented Apr 25, 2016

So I had this problem also. What I discovered was that I was using <base href="/My.App.Web/"> and accessing it in the browser on localhost/my.app.web/somepage/... when the error occurs. Changing it to <base href="/my.app.web/"> seems to do the trick but now I would get the error when requesting localhost/My.App.Web/somepage/.... So I asume something in the html5mode is checking case sesitive addresses.

Update:
I'm using angular v1.4.10 and angular-ui-routing v0.2.18

@anil826
Copy link

anil826 commented Feb 12, 2017

Finally I got a way to to solve this issue by server side as it's more like an issue with AngularJs itself I am using 1.5 Angularjs and I got same issue on reload the page.
But after adding below code in my server.js file it is save my day but it's not a proper solution or not a good way .

app.use(function(req, res, next){
  var d = res.status(404);
     if(d){
     	res.sendfile('index.html');
     }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests