Reputation: 6563
I'm using SPA technique using AngularJS in ASP.NET MVC framework,AngularJS routing between pages are working fine when it's run from VS2013,but after hosting the application in to IIS8.5 routing not working.
When i run the app using IIS express the url was http://localhost:12345/#/home After publishing http://localhost/myapp/#/home
Here is my app.js,
$routeProvider.when("/home", {
controller: "homeController",
templateUrl: "/app/views/home.html"
});
In index.html
<li> <a href="#/home">Home</a></li>
When i publish my app in windows azure, app is working fine. Because the url was myapp.azurewebsite.net
. myapp.azurewebsite.net/#/home
How can i host similarly in local IIS.
Upvotes: 1
Views: 1592
Reputation: 303
You almost find find the answer -- that is all about absolute file path.
Quick fix:
Change templateUrl: "/app/views/home.html"
to templateUrl: "app/views/home.html"
(remove the heading slash)
Answer:
If you specify the templateUrl
as /app/views/home.html
, which starts with /
, you tell the browser to get it from root.
If your webapp is stored in http://localhost/myapp/
, your browser will visit http://localhost/app/views/home.html
to get the template.
That also explains why your app works fine when it is places in root directory, but not working in sub directories, like http://localhost/myapp/#/home
.
Do not worry about the side effect of relative path. All the resources are calculated relative to index.html
.
Upvotes: 1