Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

I was having a lot of trouble getting Angular routing to work when the url was not the root of the webserver.
i.e. http://localhost/MyWebsite/ instead of http://localhost/

I messed around with all the routing configs and eventually got this:

angular.module('myApp', ['myApp.ctrl.home','ngRoute'])
.config(['$routeProvider', '$locationProvider', function ($routeProvider,   $locationProvider) {

    // Specify the three simple routes ('/', '/About', and '/Contact')
    $routeProvider.when('/', {
        templateUrl: '/MyWebsite/Home/Home',
        controller: 'homeCtrl',
    });
    $routeProvider.when('/About/', {
        templateUrl: '/MyWebsite/Home/About',
        controller: 'aboutCtrl',
    });
    $routeProvider.otherwise({
        redirectTo: '/squiffy'
    });
    $locationProvider.html5Mode(false).hashPrefix('!');
}]);

and adding < base href="/MyWebsite/" /> to my html head element. So the url's now form correctly (http://localhost/MyWebsite/#!/About )

And now it all works in chrome! Excellent, go me!
But it doesn't work in IE.

The developer console gives me the error:

 Error: [$compile:tpload] Failed to load template: /Home/About (HTTP status: 404 Not Found)  

So it appears it is looking for /Home/About instead of /MyWebsite/Home/About

Ideally I don't want to have to hardcode the /MyWebsite/... to the template url's.
But mainly i just want to get something working across all (most) browsers.

It's an .NET MVC 5 web site, i can give you any code from the controllers or route config if needed but it's all pretty much as basic as you can get.
1 controlelr with 1 ActionResult returning a PartialView for each page, 1 cshtml page with some html filler text, routeconfig is default..

(NB, it works in all browsers when i use the root website, remove the tag and remvoe the /MyWebsite/ from the templateUrl's.)

So any idea where I am going wrong?

share|improve this question
    
If you are not really using any of the extra features from MVC5, I would suggest just serve one single Index.cshtml, route everything to that index using DefaultRouteHandler, and let Angular handle the routing fully using ngRoute. just my 2cents though – CozyAzure Aug 3 at 12:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.