我的网址看起来像这样
http://127.0.0.1:50884/index.html#/home
http://127.0.0.1:50884/index.html#/home
这是索引页面.我使用角度ui-router来改变各种视图,但url带有#tag,如下所示:
http://127.0.0.1:50884/index.html#/mobileOperator
http://127.0.0.1:50884/index.html#/contentExpertise
题 :
有没有办法从url中删除/清除#tag ..以显示如下所示的url路径:
http://127.0.0.1:50884/index.html/home
http://127.0.0.1:50884/index.html/contentExpertise
我尝试了html5mode,但它在控制台中给出了角度错误.
Error: [$location:nobase] http://errors.angularjs.org/1.5.0-rc.2/$location/nobase K/<@http://127.0.0.1:50884/js/angular-v1.5.min.js:6:421 pf/this.$get<@http://127.0.0.1:50884/js/angular-v1.5.min.js:110:96 h/<.invoke@http://127.0.0.1:50884/js/angular-v1.5.min.js:41:293 gb/F<@http://127.0.0.1:50884/js/angular-v1.5.min.js:43:96 d@http://127.0.0.1:50884/js/angular-v1.5.min.js:40:270 e@http://127.0.0.1:50884/js/angular-v1.5.min.js:41:1 h/<.invoke@http://127.0.0.1:50884/js/angular-v1.5.min.js:41:86 gb/F<@http://127.0.0.1:50884/js/angular-v1.5.min.js:43:96 d@http://127.0.0.1:50884/js/angular-v1.5.min.js:40:270 e@http://127.0.0.1:50884/js/angular-v1.5.min.js:41:1 h/<.invoke@http://127.0.0.1:50884/js/angular-v1.5.min.js:41:86 gb/F<@http://127.0.0.1:50884/js/angular-v1.5.min.js:43:96 d@http://127.0.0.1:50884/js/angular-v1.5.min.js:40:270 e@http://127.0.0.1:50884/js/angular-v1.5.min.js:41:1 h/<.invoke@http://127.0.0.1:50884/js/angular-v1.5.min.js:41:86 s/</<@http://127.0.0.1:50884/js/angular-v1.5.min.js:52:121 n@http://127.0.0.1:50884/js/angular-v1.5.min.js:7:364 s/<@http://127.0.0.1:50884/js/angular-v1.5.min.js:52:90 h/<.invoke@http://127.0.0.1:50884/js/angular-v1.5.min.js:41:293 e/<@http://127.0.0.1:50884/js/angular-v1.5.min.js:38:458 h/<.invoke@http://127.0.0.1:50884/js/angular-v1.5.min.js:41:293 gb/F<@http://127.0.0.1:50884/js/angular-v1.5.min.js:43:96 d@http://127.0.0.1:50884/js/angular-v1.5.min.js:40:270 K@http://127.0.0.1:50884/js/angular-v1.5.min.js:71:447 la@http://127.0.0.1:50884/js/angular-v1.5.min.js:60:266 R@http://127.0.0.1:50884/js/angular-v1.5.min.js:58:229 R@http://127.0.0.1:50884/js/angular-v1.5.min.js:58:397 R@http://127.0.0.1:50884/js/angular-v1.5.min.js:58:397 N@http://127.0.0.1:50884/js/angular-v1.5.min.js:56:263 Ac/c/</<@http://127.0.0.1:50884/js/angular-v1.5.min.js:21:99 sf/this.$get</m.prototype.$eval@http://127.0.0.1:50884/js/angular-v1.5.min.js:140:363 sf/this.$get</m.prototype.$apply@http://127.0.0.1:50884/js/angular-v1.5.min.js:141:83 Ac/c/<@http://127.0.0.1:50884/js/angular-v1.5.min.js:21:57 h/<.invoke@http://127.0.0.1:50884/js/angular-v1.5.min.js:41:293 Ac/c@http://127.0.0.1:50884/js/angular-v1.5.min.js:20:1 Ac@http://127.0.0.1:50884/js/angular-v1.5.min.js:21:274 de@http://127.0.0.1:50884/js/angular-v1.5.min.js:20:83 @http://127.0.0.1:50884/js/angular-v1.5.min.js:306:372 n.Callbacks/i@http://127.0.0.1:50884/js/jquery-2.2.1.min.js:2:27060 n.Callbacks/j.fireWith@http://127.0.0.1:50884/js/jquery-2.2.1.min.js:2:27828 .ready@http://127.0.0.1:50884/js/jquery-2.2.1.min.js:2:29619 J@http://127.0.0.1:50884/js/jquery-2.2.1.min.js:2:29804 "
请帮忙
解决方法
默认情况下,AngularJS将使用主题标签路由URL.
使用AngularJS中的$locationProvider很容易获得干净的URL并从URL中删除主题标签.
您需要将$locationProvider注入模块的config部分,并使用HTML5 History API.
例如
使用AngularJS中的$locationProvider很容易获得干净的URL并从URL中删除主题标签.
您需要将$locationProvider注入模块的config部分,并使用HTML5 History API.
例如
app.config(function ($stateProvider,$urlRouterProvider,$locationProvider) { $stateProvider .state('home',{ url: '/home',templateUrl: 'partial-home.html' }) .state('about',{ url: '/aboutus',templateUrl: 'aboutus.html' }); $locationProvider.html5Mode(true); });
另外别忘了放一个< base href =“/”> index.html里面的标签.