Angular JS deep-link and browser refresh

I am building an angular-js based single-page solution. I thought my deep-linking was working, forward and back browser history works fine. But if I refresh (F5) the single record page... bootstrap and angular don't seem to load and the page displays incorrectly. So I am expecting /owners to provide a list and /owners/XYZ to provide the XYZ single owner record.

The error I receive indicates Chrome is not interpreting this as html - failing on the first css link... but it is deep-linking - when using the browsers history ok. When I refresh I get the error ->> Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://myfakedomain.com/owners/css/bootstrap.css".

Ok the code - Here I hook up the routeProvider:

.config(['$routeProvider','$locationProvider', function ($routeProvider, $locationProvider) {
$locationProvider.html5Mode(true).hashPrefix("!");
$routeProvider
    .when('/owners', {templateUrl: '/partials/owner-list.html',  controller:OwnerListCtrl})
    .when('/owners/:name', {templateUrl: '/partials/owner-details.html',   controller:OwnerCtrl})
     .when('/', {templateUrl:'/partials/home.html', controller:HomeCtrl})
    .otherwise({redirectTo:'/home'});
}]);

2 simple controllers that are relevant here... the backend is a factory service for retrieval from a RESTful webservice.

function OwnerListCtrl($scope, $routeParams, backend) {
var ug = $( "#ug" ).html();
var mydata = null;

// load the params coming from the UI
if (($routeParams != null)&& ($routeParams.nm != null))
    mydata = $routeParams.nm;
else{
    // in case we get here directly - ensure only super users
    // will access other owner entities
    if (ug != SUPERUSER)
        mydata = $( "#on" ).html();     
}
backend.owners(mydata).then(function (result){
        $scope.owners = result.data.data;
});
$scope.orderProp = 'name';
}

And the single record controller...

function OwnerCtrl($scope, $routeParams, $http, backend,$log, $location){
    // populate the companys select dropdown
    $scope.companys=function(){
        backend.companys().then(function (response){
            $scope.companies = response.data.data;
        })
    }
    if (($routeParams == null) && ($routeParams.name == null)){
        var ug = $( "#ug" ).html();
        var myParam = null;

        if (ug != SUPERUSER)
            myParam = $( "#on" ).html();

        backend.owners(myParam).then(function (result){
            $scope.owner = result.data.data[0];
            $scope.companys();
        });
    }else{
        backend.owners($routeParams.name).then(function (result){
            $scope.owner = result.data.data[0];
            $scope.companys();
            $log.info($location.url());
        });     
    }

}

Any insights would be welcomed.

I think that this is a routing issue. If you look at the path to the css file its attempting to load from myfakedomain.com/owners/css/bootstrap.css, i'm assuming it should be myfakedomain.com/css/bootstrap.css. Are the paths relatively defined in your html file?

I think you need to use absolute paths for the linked files, js and css both. You need to set up a .htaccess file in the root directory that rewrites all requests to index.html, assuming that is your angular application. Here is the suggested solution:

# if a directory or a file exists, use it directly
#RewriteCond %{REQUEST_FILENAME} -s [OR]
#RewriteCond %{REQUEST_FILENAME} -l [OR]
#RewriteCond %{REQUEST_FILENAME} -d
#RewriteCond %{REQUEST_URI} !/api
#RewriteRule ^.*$ - [NC,L]

# otherwise forward it to index.html
#RewriteRule ^app/(.*) /app/#/$1 [NC,L]

However, a simplified version works for me, my application subdirectories are in the root folder, rather than the app folder as in the example. This works for my case

RewriteEngine on
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.html [L]

Hope this helps.