In my angular app I am trying to change the location to "#home"
when the user enters an invalid route.
Here's a short but complete app demonstrating what I did.
<!DOCTYPE html>
<html>
<head>
<script src="angular.js"></script>
<script>
angular.module('app', [])
.controller('ctrl', function($scope, $location, $window) {
$scope.$watch (function() { return $location.url() }, function(url) {
if (url == '')
$window.location = '#home'
})
})
</script>
</head>
<body ng-app="app" ng-controller="ctrl"></body>
</html>
But when I do this I get an infdig
error when the page loads. I don't know whats wrong.
Edit: I don't want to use routing libraries like "ui-router". so answers like this one that uses the "angular-route" library are not helpful.