Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular app on IIS 8.x virtual directory has strange URL behavior

I'm having a problem with Angular JS on IIS 8.x with MVC. My application index page with virtual directory is like so:

https://myapp.xyz/VirtualDirectory/

That page loads the angular app. My angular routes are set up as:

$routeProvider
.when('/', {
    templateUrl: 'Content/Partials/Home/Index.html'
})
.when('/Error', {
    templateUrl: 'Content/Partials/Shared/Error.html'
})
.otherwise({
    redirectTo: '/Error'
});

So, if I access the first link, my URL looks like:

https://myapp.xyz/VirtualDirectory/#/

This works perfectly and resolves my partials fine. Angular requests the partials with the virtual directory in it so I see an HTTP request to:

https://myapp.xyz/VirtualDirectory/Content/Partials/Home/Index.html

However, if I access without a trailing slash like:

https://myapp.xyz/VirtualDirectory

Angular routes to:

https://myapp.xyz/VirtualDirectory#/

Once this happens, none of my routes work (they do not respect the virtual directory). They route as:

https://myapp.xyz/Content/Partials/Home/Index.html

This breaks all of my routes and templates defined in my directives. Any suggestions on how to fix this issue?

like image 385
Adam Modlin Avatar asked Jun 02 '14 16:06

Adam Modlin


1 Answers

try to add this in you head tag.

<html>
<head>
    <base href="/VirtualDirectory/">
</head>
<body>
    ...
</body>
like image 195
1st4ck Avatar answered Nov 11 '22 00:11

1st4ck