HTML5 mode with Phonegap and AngularJS

后端 未结 3 1122
失恋的感觉
失恋的感觉 2021-02-08 17:02

I\'m trying to make AngularJS html5 mode (true) works with Phonegap. I did a lot of search before to post this, I tried different combination of configurations, adding the

3条回答
  •  终归单人心
    2021-02-08 17:49

    In order to get around this problem with an existing website, I add a angularjs constant at build time that indicates whether or not the build is for phonegap. At config time you can access constants and choose to apply html5mode.

    //Add this portion via your build scripts e.g. grunt or gulp
    //make the constant change depending on if this is a Phonegap build or not
    angular.module('myAppConstants', []).constant('PhonegapConstant', true);
    
    //How to use
    angular.module('myApp', ['myAppConstants']).config(function(
        $locationProvider,
        PhonegapConstant
    ) {
        if(!PhonegapConstant) {
            $locationProvider.html5mode(true);
            $locationProvider.hashPrefix('!');
        }
    });
    

提交回复
热议问题