HTML5 mode with Phonegap and AngularJS

后端 未结 3 1129
失恋的感觉
失恋的感觉 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 18:00

    I have just gotten this working with angularjs 1.5, the new component router, and cordova(phonegap) 6.0.

    Its a bit hacky, but here's what I had to do:

    1. Remove the tag from your html file.
    2. Set html5 mode while setting requireBase to false

    $locationProvider.html5Mode({ enabled: true, requireBase: false });

    1. Catch the cordova(phonegap) routes

      // iOS Cordova catcher
      //
      {
          path: '/var/**',
          component: 'cordova'
      },
      // Android Cordova catcher
      //
      {
          path: '/android_asset/www/index.html',
          component: 'cordova'
      }
      
    2. Make a cordova component which then reroutes to wherever you like.

          if(cookieService.loggedIn()) {
              $rootRouter.navigate(['Newsfeed']);
          }
          else {
              $rootRouter.navigate(['Title']);
          }
      

    Now the rest of your routes you can use normally. I did come up against one issue with this method though, all of my local images and svgs need to start with the full path, /android_asset/www/images for android, so I made a little filter that spits out the proper asset path for web, android, and ios.

提交回复
热议问题