AngularJS: ngRoute no longer serves from wwwroot when fixing hash-bang

44 Views Asked by At

I started out with this code, app.js:

var app = angular.module('myProject', ['ngStorage', 'ngRoute'])
    .config(function ($routeProvider) {
        $routeProvider.when("/", {
            controller: "loginController",
            controllerAs: "vm",
            templateUrl: "/index.html"
        }).otherwise({
            controller: "loginController",
            controllerAs: "vm",
            templateUrl: "/views/login.html"
        });
    });

If someone visited -

http://localhost:8885

it would redirect to http://localhost:8885/#!/ and show the index.html template the $routeProvider had declared.

And if someone visited either -

http://localhost:8885/#!/asdfasdfasdf or http://localhost:8885/#!/1234

the pages would load and show the /views/login.html template.

Everything was working fine.

Then, to exclude the hash-bang, known as (/#!/), I added:

$locationProvider.html5Mode(true) to the end of the config mentioned above.

This caused my project to no longer serve my src -> MyProject -> wwwroot folder files anymore, but rather the content inside of my src -> Views -> App -> Index.html file. File structure shown below:

Visual Studio ASP.Net

Why is this the case? How do I solve this to not only exclude the hash-bang but also to serve from my wwwroot folder?

EXTRA INFO -

My _Layout.cshtml file has this for a body:

<body ng-view>
    <div>
        @RenderBody()
    </div>
</body>

I've also tried to place <base href="/"> inside the <head> but it didn't work.

Any help?

0

There are 0 best solutions below