在我的角度页我使用 $ locationProvider
。但它不是在我的网页的工作。我在控制台这样遇到错误,的在HTML5模式$位置需要一个标签是present!的。所以我添加一个<基本href =//>
,也不能在我的角度网页的工作。在这里,我提到我的目录结构和我的code。
下面我样本项目链接了。帮我解决这个问题。
我的目录结构
IWA(根目录下) > JS > LIB - > angular.js - > angular.route.js - > app.js >意见 - > home.html做为 - > about.html - >的index.html
的index.html
<!DOCTYPE HTML> < HTML NG-应用=inQueueWeb> <头LANG =ENGT&; <间的charset =UTF-8> <脚本SRC =JS / lib目录/ angular.js>< / SCRIPT> <脚本SRC =JS / lib目录/角route.js>< / SCRIPT> < /头> <身体GT; < DIV NG-视图>< / DIV> < /身体GT; <脚本SRC =JS / app.js>< / SCRIPT> < / HTML>
app.js
VAR IWA = angular.module('inQueueWeb',['ngRoute']); iwa.config(['$ routeProvider','$ locationProvider',函数($ routeProvider,$ locationProvider){$ routeProvider 。当(/,{templateUrl:意见/ home.html做为'}) 。当(/休息,{templateUrl:意见/ about.html'});$ locationProvider.html5Mode(真);}]);
和我也尝试了这些
$ locationProvider.html5Mode({启用:真,requireBase:假});$ locationProvider.html5Mode(真).hash preFIX(!);
解决方案
您是在正确的轨道上。你必须添加 $ locationProvider.html5Mode(真)
到应用的的.config()
方法,然后添加<基本href =/>
到您的HTML头。我想你已经做到了这一点。
什么错误是这样的:以 $ locationProvider.html5Mode(真)
,一个hashbang( /#我的页面
)网址是没有必要的。一个URL,简直是 /我的页面
,没有散。您需要更新的链接在你的的意见/模板/ header.html中
,以适应这一点。
我已经更新:
您 app.js
添加 $ locationProvider.html5Mode(真)
。您 index.html的
添加<基本href =/>
和您的意见/模板/ header.html中
来调整锚链接。我希望这是有帮助的!您可以下载档案与文件调整这里。
In my angular page i'm using a $locationProvider
. But it's not working in my web page. I got error in my console like this, $location in HTML5 mode requires a tag to be present!. so i add a <base href="/" />
, which also not working in my angular page. Here i mentioned my directory structure and my code.
Here my sample Project link too. Help me out to resolve this problem.
my directory structure
iwa (root directory)
> js
> lib
-> angular.js
-> angular.route.js
-> app.js
> views
-> home.html
-> about.html
-> index.html
index.html
<!DOCTYPE html>
<html ng-app="inQueueWeb">
<head lang="en">
<meta charset="UTF-8">
<script src="js/lib/angular.js"></script>
<script src="js/lib/angular-route.js"></script>
</head>
<body>
<div ng-view></div>
</body>
<script src="js/app.js"></script>
</html>
app.js
var iwa = angular.module('inQueueWeb', ['ngRoute']);
iwa.config(['$routeProvider','$locationProvider', function($routeProvider,$locationProvider) {
$routeProvider
.when("/", {templateUrl: 'views/home.html'})
.when("/rest", {templateUrl: 'views/about.html'});
$locationProvider.html5Mode(true);
}]);
And also i tried these
$locationProvider.html5Mode({enable: true, requireBase: false});
$locationProvider.html5Mode(true).hashPrefix('!');
解决方案
You're on the right track. You've got to add $locationProvider.html5Mode(true)
to your app's .config()
method, and then add a <base href="/">
to your HTML head. I think you've done this already.
What's going wrong is this: with $locationProvider.html5Mode(true)
, a hashbang (/#mypage
) URL isn't necessary. A URL would simply be /mypage
, without the hash. You need to update the links in your views/templates/header.html
to suit this.
I've updated:
Yourapp.js
to add $locationProvider.html5Mode(true)
.
Your index.html
to add <base href="/">
, and
Your views/templates/header.html
to adjust the anchor links.
I hope this was helpful! You can download an archive with the adjusted files here.
下一篇:角UI网的分组报头报头、UI