我正在使用cordova构建一个Android应用程序。我使用angularjs ui-router进行路由。 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>
答案 0 :(得分:0)
确保您的html Content-Security-Policy
代码中包含head
元元素。
类似的东西:
<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://*">
有关适合您情况的正确安全选择的更多信息,请参阅this link。