【问题标题】:AngularJS app URLAngularJS 应用程序 URL
【发布时间】:2014-03-10 07:21:19
【问题描述】:

我在我的 AngularJS 应用程序中使用 ngRoute 来构建不同的应用程序路由,下面是我的 app.js 的一部分。现在我面临的问题是 URL 显示为( localhost/myapp/index.html#/home ),而我的客户需要在 localhost/myapp#/home ,所以我想知道如何获取 index.html等式或至少将其设置为没有.html的localhost/myapp/index#/home?谢谢

var myApp = angular.module('myApp', ['ngRoute','ngSanitize']).
 config(['$routeProvider', function($routeProvider) {
    $routeProvider.when('/home', 
                  { templateUrl: 'templates/home.html', 
                    controller: 'homeController'
                  });
   $routeProvider.when('/about', 
                  {templateUrl: 'templates/aboutus.html', 
                   controller: 'aboutUsController'
                  }); 
   $routeProvider.otherwise({redirectTo: '/home'}); }]);

【问题讨论】:

  • 我认为这是服务器问题,与角度无关。
  • 如果您在 IIS 中托管网站,您可以使用 URL 重写模块 iis.net/downloads/microsoft/url-rewrite
  • 我正在本地 XAMPP 上进行测试,那么它可能是什么服务器端问题?

标签: javascript angularjs


【解决方案1】:

您应该能够通过 $locationProvider.html5Mode(true)<html><head><base href="/myApp"> 的组合来做到这一点

【讨论】:

    猜你喜欢
    • 2017-05-12
    • 2015-04-18
    • 2013-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-15
    • 2013-04-21
    • 2018-12-20
    相关资源
    最近更新 更多