0

我正在使用 AngularJS 1.3。我的项目 url 是http://localhost/MyProject/app/#/index.html 我想在 url http://localhost/MyProject/index.html打开 index.html 我该怎么做?谁能帮忙?谢谢

angular.module('myapp').config(['$stateProvider', '$urlRouterProvider', '$httpProvider', '$locationProvider', function ($stateProvider, $urlRouterProvider, $httpProvider, $locationProvider) {
    $urlRouterProvider.otherwise('/');
    $stateProvider.state('index', {
        url: '/',
        controller: 'homeController',
        templateUrl: 'templates/home_page.html'
    }) $locationProvider.html5Mode(true);
}]);

如果我使用

<base href="index.html">

代替<base href="/"> 页面一半加载有许多不安全的类型错误。

4

2 回答 2

0

将以下内容添加到您的 angular.config :

$locationProvider.html5Mode(true);

在 index.html 文件中:

<head>
    <meta charset="utf-8">

    <base href="/">
</head>

更多信息,检查角度文档以获取 $location

于 2016-08-10T11:49:17.617 回答
0

你需要在你的配置中添加

$locationProvider.html5Mode({
    enabled: true
});

然后你必须在你的文档中设置一个以使用相对链接。

<base href="/">

于 2016-08-10T11:44:06.873 回答