Reputation: 379
Home page I am using AngularJS with my ASP.Net MVC application and I am using angular routing but it is not working.
The angular routes are defined as:
var app = angular.module("webApp",['ngRoute']);
app.config(function($routeProvider){
$routeProvider.when(
"/",{
templateUrl: "home/dashboard",
controller: "webCtrl"
})
.when(
"/page1",{
templateUrl: "home/contact",
controller: "page1Ctrl"
})
.otherwise({
templateUrl: "home/contact",
controller: "page1Ctrl"
});
});
The navigation links are displayed on index.cshtml
as given below:
<body ng-app="webApp">
<a href="#/">Home</a>
<a href="#page1">Page1</a>
<div ng-view></div>
</body>
It displays dashboard
when launched but doesn't display contact
page when second link is clicked. Also, it displays strange URLs. On the homepage it dislays http://localhost:58193/#!/
and when I click on page1
link URL gets changed to http://localhost:58193/#!/#%2Fpage1
.Please let me know if I am mistaking anything.
Upvotes: 0
Views: 1835
Reputation: 3778
have you tried to do like this?
var app = angular.module("webApp",['ngRoute']);
app.config(function($routeProvider){
$routeProvider.when(
"/",{
templateUrl: "/home/dashboard",
controller: "webCtrl"
})
.when(
"/page1",{
templateUrl: "/home/contact",
controller: "page1Ctrl"
});
$routeProvider.otherwise({ redirectTo: "/page1" });
$locationProvider.hashPrefix("!");
});
then:
<body ng-app="webApp">
<a ng-href="#!page1">Page1</a>
<div ng-view></div>
</body>
and maybe put in your index-html in your section this:
<meta name="fragment" content="!">
<base href="/">
Upvotes: 1