Search code examples
angularjsngrouteroute-provider

$routeProvider.when('/', ...) has no effect, when html5 mode is on


Solution to the problem: url you write in base tag should have a trailing slash.

I have the following routes configuration, but template is not requested, if html5 mode is on. No errors, no attempts to get the resource from the server. Neither changing base url, nor setting prefix with hasPrefix('!') has no effect on this behavior

   angular
        .module('beneficiaryBanks')
        .config(configRoutes);

configRoutes.$inject = ['$routeProvider','$locationProvider'];
function configRoutes($routeProvider, $locationProvider) {
    $routeProvider
        .when('/',
        {
            controller: 'beneficiaryBanksListController',
            controllerAs: 'listVM',
            templateUrl: 'BeneficiaryBanksList.cshtml'
        });
    $locationProvider.html5Mode(true);
}

It looks like angular does not match current url with '/'.

update 1
Debugging shows that for url http://localhost:8080/APS/Home/BeneficiaryBanksModule and base address APS/Home/BeneficiaryBanksModule angular sees route as /BeneficiaryBanksModule which does not match with /, whereas route becomes just a / when html5 mode is disabled.


Solution

  • The problem was in base tag. If it does not end with slash / angular treats last part as a file name and drops it.

    That's why I saw /BeneficiaryBanksModule instead of /