1

I'm using Angular ngRoute.

When I'm trying to route to another page, it is not redirecting in URL. It shows as http://localhost:58317/#!#%2Fstudents

myApp.js

var app = angular.module('MyApp', ['googlechart', 'ngRoute'])
app.controller('HomeCtrl', function ($scope) {
    $scope.msg = "Hello Angular.....";
})

app.config(function ($routeProvider, $locationProvider) {
    $locationProvider.html5Mode(false);
    $locationProvider.hashPrefix("!");
    $routeProvider.when("/home", {
        templateUrl: '/Home/part1',
        controller: 'routeDemoFirstController'
    }).
    when('/contact', {
        templateUrl: '/Home/part2',
        controller: 'routeDemoSecondController'
    }).
     when('/students', {
         templateUrl: '/Home/part2',
         controller: 'routeDemoSecondController'
     })
})

Index.cshtml This is my .cshtml code Here i write anchor tag

<div class="row">
    <div>
        <a href="/#/home">Home</a>
        <a href="#/contact">Courses</a>
        <a href="#/students">Students</a>
    </div>
    <ng-view></ng-view>
</div>
Mistalis
  • 17,793
  • 13
  • 73
  • 97

2 Answers2

2

You are using the hash-bang prefix:

$locationProvider.hashPrefix("!");

It signicates that your URL should be:

<a href="#!/home">Home</a>

If you want to remove the ! from the URL (you can also remove the #), you can check this answer.

Community
  • 1
  • 1
Mistalis
  • 17,793
  • 13
  • 73
  • 97
0

remove

$locationProvider.hashPrefix("!");

Make changes to html

<div class="row">
        <div>
            <a ng-href="#!/home">Home</a>
            <a ng-href="#!/contact">Courses</a>
            <a ng-href="#!/students">Students</a>
        </div>
        <ng-view></ng-view>
    </div>
Ravi Rajput
  • 539
  • 4
  • 12