0

This is strange to me, as I cannot seem to see the error, maybe another pair of eyes will help.

This is the base html:

<body ng-controller="base_ctrl">
<div class="container-fluid">
    <div class="row">
        <div class="col-sm-12 main_container">
            <a href="#about_us">About Us Link</a>
            <a href="#home">Home Link</a>
        </div>
    </div>
    <div ng-view></div>
</div>
</body>

And this is the js:

var app = angular.module('example_app', ['ngRoute']);


app.config(function($routeProvider, $locationProvider){
$routeProvider

.when('/', {
    templateUrl: 'home.html',

})

.when('/about_us', {
    templateUrl: 'about_us.html',

})

.otherwise({
    redirectTo: '/'
});

    $locationProvider.html5Mode({
        enabled: true,
        requireBase: false
    });

});

app.controller('base_ctrl', function($scope){

});

This should work when i look at it, but it does not. When you click on a link, the url changes to home or about_us, depending on which you click, but the ng-view does not change.

Josh Winters
  • 829
  • 5
  • 12
  • 27
  • 1
    Possible duplicate of [angularjs 1.6.0 (latest now) routes not working](http://stackoverflow.com/questions/41211875/angularjs-1-6-0-latest-now-routes-not-working) – Claies May 11 '17 at 10:52
  • beyond that, does it work if you change your `href` and remove the `#`? that's the point of enabling `html5Mode`, after all.... – Claies May 11 '17 at 10:54
  • no. if you remove the location provider and just do the base route provider, it still doesnt work. – Josh Winters May 11 '17 at 11:08
  • that's not what I asked. You have, for example, `href="#home"`, which is an *anchor link*. in angular 1.6, routes were changed to `!#home` instead, to avoid conflicts with anchor links. on top of that, having `html5Mode` enabled creates links that are just `home`, while still allowing `#` anchor links to work. so *either* change the link to `href="home"` or `href="!#home`, depending on if you want `html5Mode` or not. – Claies May 11 '17 at 11:13
  • ok, but the links still dont work. Changing the href to !#about_us for example, provides the right route in the url, but nothing changes in my ngview. Do i have to change something in the config? – Josh Winters May 11 '17 at 11:24
  • works fine from what I can reproduce: http://plnkr.co/edit/W1PyecmmHs6gX1EGp3B8?p=preview. can you show an example of this doing what you describe? your code you provided here seems fine. – Claies May 11 '17 at 11:31
  • thats because you are using 1.5, which is what i have switched to, 1.5.11, and routing works fine. No idea why 1.6.4 routing doesnt work though. Weird, now it works. go figure. I used the same configuration that works in 1.5, and just changed the cdn's to 1.6.4, and it works fine. – Josh Winters May 11 '17 at 11:32
  • eh? the plunker I posted is 1.6.4, the same version you mention in the question. sorry I didn't update the description when I updated the file versions, but it is definitely 1.6.4 – Claies May 11 '17 at 11:33
  • on that note, are you *sure* that you have matching versions between angular.js and angular.route.js? if these are mismatched versions, then strange things can happen, and/or routing can fail completely. – Claies May 11 '17 at 11:36

0 Answers0