Valyrion
Valyrion

Reputation: 2603

AngularJS routed page refresh never loads

I'm trying to use AngularJS in a salesforce local hybrid android app, and while a simple test of the angular code works in firefox, when I run it in the Android emulator it loads for a fraction of a second and is replaced with a blank screen.

I've noticed that refreshing the page after routing ( going to [URL]/index.html#/ after the first page load ) ends up with an eternal 'ajax loading' spinner. I suspect this might be the root of my problem. My routing code looks like this:

var contactlistModule = angular.module("AugmentedContactList", ['ngRoute']);

contactlistModule.controller(ContactlistController);

contactlistModule.config(['$routeProvider', function($routeProvider) {
    $routeProvider.when('/', {
        controller: 'ContactlistController',
        templateUrl: 'viewparts/contactlistview.html'
    }).when('/contact', {
        controller: 'ContactController',
        templateUrl: 'viewparts/contact.html'
    }).otherwise({
        redirectTo: '/'
    });
}]);

Why does this refreshing error happen? Shouldn't going to index.html have the same effect as index.html#/ ?

Upvotes: 1

Views: 1155

Answers (1)

link
link

Reputation: 1676

I guess going to index.html without enabling html5Mode won't work as you expect.

You can enable it by injecting $locationProvider and adding this line to your config:

$locationProvider.html5Mode(true);

However, be aware that to enable html5 mode you will need to configure your server to return index.html (or whatever your main page is) on every URL request.

See also:

$locationProvider docs

Upvotes: 1

Related Questions