angularjshtmlcordovaangular-ui-routerangular-ui-router-extras

angularjs cordova base href


trying to set the correct base href value for an angularjs html5 web app to work in cordova

initially using $locationProvider.html5Mode(true) with <base href="/">:

Tried a few alternatives are floated around here on SO and ui-router FAQs:

<base href="."> with html5 mode as per this answer :

<base href="./"> with html5 mode:

no base href with $locationProvider.html5Mode({enabled: true, requireBase: false});

my app config definition looks like:

myApp.config(['$locationProvider', '$urlRouterProvider', '$stateProvider', '$stickyStateProvider', function($locationProvider, $urlRouterProvider, $stateProvider, $stickyStateProvider) {

    $locationProvider.html5Mode(true);

    $stateProvider
    .state('root', {            // we define a 'root' state so that we can load some essential data prior to any template being loaded
        url: '',
        abstract: true,
        sticky: true,
        views: {
            'root': {
                template: '<ui-view/>',
            }
        }
    })
    .state('root.worldmap', {
        url : '/worldmap',
        templateUrl : 'templates/worldmap.tmpl.html'
    })
    .state('root.faq', {
        url : '/faq',
        templateUrl : 'templates/faq.tmpl.html'
    })
    .state("otherwise", {
        url: "*path",
        views: {
            'root': {
                template: "",
                controller: ['$injector', function($injector) {
                    var $state = $injector.get("$state");
                    $state.go('root.worldmap');
                }]
            }
        },
    });
    $stickyStateProvider.enableDebug(true);
}]);

For info: using this method of alternative cordova deviceready vs angular.element bootstrap for cordova / browser respectively


Solution

  • OK so the way to get this working is by removing the base href AND disabling html5 mode :

    Don't forget to run cordova build ios (after you grunt / gulp etc to compile the js files)
    ...this ensures the files in the cordova /platforms/ios/www directory are updated.