ui sref无法在cordova安卓应用程序中工作



我正在使用cordova构建一个android应用程序。我使用angularjs-ui路由器进行路由。ui sref根本不起作用。以下是我的代码:

var angularApp = angular.module('angularApp', [
  'ui.router',
  'ngTouch',
  'angular.filter',
  'angularApp.services',
  'angularApp.controller',
]);
angularApp.config(function($stateProvider, $locationProvider, $urlRouterProvider) {
  $stateProvider
    .state('home', {
      url: '/home',
          templateUrl: 'templates/home.html',
    })
    .state('settings', {
      url: '/settings',
          templateUrl: 'templates/settings.html',
    });
    $urlRouterProvider.otherwise('/home');
  });

默认情况下,主状态加载,当我单击设置链接时,它不起作用。

这是index.html 中的代码

<!DOCTYPE html>
<!--
    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at
    http://www.apache.org/licenses/LICENSE-2.0
    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.
-->
<html>
    <head>
        <!--
        Customize this policy to fit your own app's needs. For more guidance, see:
            https://github.com/apache/cordova-plugin-whitelist/blob/master/README.md#content-security-policy
        Some notes:
            * gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication
            * https://ssl.gstatic.com is required only on Android and is needed for TalkBack to function properly
            * Disables use of inline scripts in order to mitigate risk of XSS vulnerabilities. To change this:
                * Enable inline JS: add 'unsafe-inline' to default-src
        -->
        <!-- <meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'"> -->
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui">
        <meta name="format-detection" content="telephone=no">
        <link rel="stylesheet" type="text/css" href="css/index.css">
        <link rel="stylesheet" href="css/custom.css">
        <link rel="stylesheet" href="css/icomoon.css">
        <!-- Path to Framework7 Library CSS-->
        <link rel="stylesheet" href="lib/framework7/css/framework7.material.min.css">
        <link rel="stylesheet" href="lib/framework7/css/framework7.material.colors.min.css">
        <base href="file:///android_asset/www/" target="_blank">
    </head>
    <body>
        <script type="text/javascript" src="lib/angular/angular.min.js"></script>
        <script type="text/javascript" src="lib/angular/angular-ui-router.js"></script>
        <script type="text/javascript" src="lib/angular/angular-filter.min.js"></script>
        <script type="text/javascript" src="lib/angular/angular-touch.min.js"></script>
        <script type="text/javascript" src="js/angularjs-app.js"></script>
        <script type="text/javascript" src="lib/framework7/js/framework7.min.js"></script>
        <div id="welcome-wrap">
            <div class="logo"><img src="img/logo.png"/></div>
            <div class="preloader"></div>
        </div>
        <div ng-include="'templates/common-left-panel.html'"></div>
        <div class="views">
          <!-- Your main view, should have "view-main" class-->
            <div class="view view-main">
                <div class="navbar">
                    <div class="navbar-inner">
                        <div class="left">
                            <a href="#" class="link icon-only open-panel"> <i class="icon icon-navicon"></i></a>
                        </div>
                        <div class="center">
                            <h3>app</h3>
                        </div>
                        <div class="right">
                            <a href="#" class="link icon-only search-icon"> <i class="icon icon-search"></i></a>
                            <a ui-sref="settings" class="link icon-only setting-icon"> <i class="icon icon-gear"></i></a>
                        </div>
                    </div>
                </div>
                <!-- Main page content with bottom tab bar  -->
                <div class="pages navbar-fixed">
                <a href="#/settings">Settings</a>
                    <div ui-view></div>
                </div>
            </div>
        </div>
        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript" src="js/framework-app.js"></script>
        <script type="text/javascript" src="js/controllers.js"></script>
        <script type="text/javascript" src="js/services.js"></script>
    </body>
</html>

确保在html head标记中有一个Content-Security-Policy元元素。

类似的东西:

<meta http-equiv="Content-Security-Policy" content="default-src * 'self' 'unsafe-inline' 'unsafe-eval' data: gap: ; connect-src * data: blob: filesystem:; font-src * 'self' filesystem: ; style-src 'self' 'unsafe-inline'; media-src * 'self' filesystem: ; img-src * 'self' data: filesystem: ; frame-src 'self' gap://*">

有关在您的情况下正确的安全选择的更多信息,请参阅此链接。

相关内容

最新更新