vendredi 28 novembre 2014

Angular html5 mode not redirecting


I am using AngularJs with Ruby on Rails.


I set the html5 option to true in angular: $locationProvider.html5Mode(true)


But now when I try to navigate through pages in my application, it will only change the URL in my browsers URL bar. But the page it self will nto change unless I reload the page. Only then will it go to the page specified.


This is how my Angular routing looks like:



@test.config(['$routeProvider', '$locationProvider', ($routeProvider, $locationProvider) ->
# Route for '/'
$routeProvider.when('/', { templateUrl: '../../views/visitors/index.html.erb', controller: 'VisitorsCtrl' } )
$routeProvider.when('/users', { templateUrl: '../../views/users/index.html.erb', controller: 'UsersCtrl' } )
# Default
$routeProvider.otherwise( { redirectTo: "/" } )

$locationProvider.html5Mode(true)
])


On the root page I have a element: <h2><a ng-click="viewUsers()">Users</a></h2>


And viewUsers() is called here:



@test.controller 'VisitorsCtrl', ['$scope', '$location', '$http', ($scope, $location, $http) ->
$scope.viewUsers = ->
$location.path('/users')
console.log("Redirected")
]


What could be needed more to get this kind of routing to work?





Aucun commentaire:

Enregistrer un commentaire