Update None of the answers or comments below help at all, I wish someone would give me the correct answer.
When I put this url below in my browser - it takes me my fruits view and works perfectly,
http://localhost:53052/AppTest.aspx#/fruits BUT when I go to my home view and click on button and try to navigate to 'fruits' view then it redirects me to http://localhost:53052/AppTest.aspx#/routeNotFound
BUT when I click on browser's back button it goes back to fruits view then if I click again then it goes back to home view.
So here is what happens in tree view,
--> Click on Home view button (should navigate to fruits view but it goes to routeNotFound view instead)
--> When I click on back button on browser, it goes to fruits view, then if I click back again then it goes to Home view
Here is my routes,
(function () { 'use strict'; var app = angular.module('fruitApp'); app.constant('routes', getRoutes()); app.config(['$routeProvider', 'routes', routeConfigurator]); function routeConfigurator($routeProvider, routes) { routes.forEach(function (route) { $routeProvider.when(route.url, route.config); }); $routeProvider.otherwise({ redirectTo: '/routeNotFound' }); } function getRoutes() { return [ { url: '/home', config: { templateUrl: 'App/templates/home.html', } }, { url: '/fruits', config: { templateUrl: 'App/templates/fruits.html', } } ]; } })(); Main View (I only use it for loading modules and loading other views into it)
<div data-ng-app="fruitApp"> <div data-ng-view=""> </div> </div> Home View
<div data-ng-controller="home as vm"> <div data-ng-click="vm.goToFruits()">click Me!</div> </div> Home Controller
(function () { 'use strict'; var controllerId = "home"; angular.module('fruitApp').controller(controllerId, ['$location', 'datacontext', home]); function home($location, datacontext) { var vm = this; vm.goToFruits = goToFruits; function goToFruits() { $location.path('/fruits'); } }; })(); Fruits View
<div data-ng-controller="fruits as vm"> fruits </div> Fruit Controller
(function () { 'use strict'; var controllerId = "fruits"; angular.module('fruitApp').controller(controllerId, ['$location', 'datacontext', fruits]); function fruits($location, datacontext) { var vm = this; }; })(); I am following this project so defining module like I do shouldn't be an issue if I am not missing any concept ?
Edit
I tried change route config and some code in controller to use ui-route instead now it takes me to the fruits view (as it was doing before) but it's not redirecting me to 'otherwise' route anymore BUT it is still changing the URL to /routeNotFound..
Update
I ended up using href and ng-href for switching views.