首页 > 解决方案 > 在 gulp 服务器中刷新 AngularJS 页面后,显示错误无法 GET

问题描述

我有一个带有 AngularJS 1.6 应用程序的 gulp 服务器。

我有一个 ng 路由器。我正在尝试#!从 url 中删除符号,所以我使用了 ng-router。我用过$locationProvider.html5Mode(true);,并且在 index.html 中我用过<base href="/">

但是当我刷新页面时它显示无法获取/ui/index.html/

我正在使用gulp服务器。

应用程序.js

var app = angular.module("apollo", ['ngRoute']);

app.config(function($routeProvider, $locationProvider) {
  $routeProvider
    .when('/ui/index.html/', {
      templateUrl: 'root.html',
      controller: 'HeaderCtrl'
    })

    .when('/ui/:appName/', {
      templateUrl: 'apps/' + localStorage.getItem('locationApp') + "/controllers/home/templates/home.template.html"
    })

    .otherwise({
      redirectTo: '/ui/index.html/'
    });
  $locationProvider.html5Mode(true);
});

索引.html

<!DOCTYPE html>
<html>
<head>
  <title>Apollo</title>
  <base href="/">
  <script src="library/angular.min.js"></script>
  <script src="library/angular-route.js"></script>
  <script src="app.js"></script>
  <script src="services/apollo-headerCtrl.js"></script>
  <script src="services/AppCtrl.js"></script>
</head>
<body ng-app="apollo">
  <div ng-view></div>
</body>
</html>

标签: javascriptangularjsgulpangularjs-ng-route

解决方案


推荐阅读