加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

在angularjs中使用html5Mode的问题

发布时间:2020-12-17 06:54:17 所属栏目:安全 来源:网络整理
导读:我正在尝试使用 angularjs中的html5Mode(true)删除url的index.html,这是代码: angular.module('myApp',[ 'ngRoute','myApp.filters','myApp.services','myApp.directives','myApp.controllers']).config(['$routeProvider','$locationProvider',function($r
我正在尝试使用 angularjs中的html5Mode(true)删除url的index.html,这是代码:

angular.module('myApp',[
  'ngRoute','myApp.filters','myApp.services','myApp.directives','myApp.controllers'
]).
config(['$routeProvider','$locationProvider',function($routeProvider,$locationProvider) {
  $locationProvider.html5Mode(true);
  $routeProvider.when('/home',{templateUrl: 'views/home.html'});
  $routeProvider.when('/about',{templateUrl: 'views/about.html'});
  $routeProvider.otherwise({redirectTo: '/'});
}]);

如果我不写$locationProvider.html5Mode(true);网址显示:

localhost:(port)/MyApplication/index.html

如果我写$locationProvider.html5Mode(true);网址显示:

localhost:(port)

MyApplication已删除网址.
我想要网址显示:

localhost:(port)/MyApplication/

我做错了什么?有什么问题?

更新:

应该如何显示我的< a>标签?现在我有:

<a href="#/about">About</>

当我点击链接时,网址显示:

localhost:(port)/MyApplication/index.html#/about

我迷失了.

提前致谢!

解决方法

如果您的应用程序在/ MyApplication /下运行,请尝试在index.html中设置基本路径并启用html5Mode:

<html>
  <head>
    <base href="/MyApplication/index.html" />
    ...

见Using $location.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读