简体   繁体   English

AngularFire浏览器刷新给出错误页面未找到

[英]AngularFire browser Refresh gives error page not Found

Scenario is, 场景是

Im new to AngularJS and making an AngularJS with AngularFire, I have defined my routing bye using $routeProvider ,see below 我是AngularJS的新手,并使用AngularFire制作了AngularJS,我使用$routeProvider定义了我的路由再见,请参见下文

var appMainModule = angular.module('appMain', [ 'firebase','ngRoute'])
.config(function ($routeProvider, $locationProvider) {
    $routeProvider.when('/', { templateUrl: '/Templates/CustomerLogin.html', controller: 'HomeCtrl' });
    $routeProvider.when('/customer/home', { templateUrl: '/Templates/CustomerHome.html' , controller:'ForLogout'});
    $routeProvider.when('/customer/singup', { templateUrl: '/Templates/CustomerSinup.html', controller: 'RegisterCtrl' });
    $routeProvider.when('/dashboard/godash', { templateUrl: '/Templates/dashboard.html', controller: 'DashboardCtrl' });
    $routeProvider.when('/customer/list', { templateUrl: '/Templates/CustomerList.html', controller: 'customerListViewModel' });
    $routeProvider.when('/customer/detail', { templateUrl: '/Templates/CustomerDetail.html', controller: 'customerDetailViewModel' });
    $routeProvider.when('/customer/googlemap', { templateUrl: '/Templates/GoogleMap.html', controller: 'MapCtrl' });
   // $routeProvider.when('/customer/postdata', { templateUrl: '/Templates/CustomerPostData.html', controller: 'AddPostCtrl' });
    $routeProvider.when('/customer/getdata', { templateUrl: '/Templates/CustomerGetData.html', controller: 'GetCtrl', reloadOnSearch: false });
    $routeProvider.when('/victim/getdata', { templateUrl: '/Templates/RiskVictimDetail.html', controller: 'VictimGetCtrl' });
    $routeProvider.otherwise({ redirectTo: '/' });
    $locationProvider.html5Mode(true);
});

this is my login controller 这是我的登录控制器

appMainModule.controller('HomeCtrl', ['$scope', '$location', 'CommonProp', '$firebaseAuth', function ($scope, $location,CommonProp, $firebaseAuth) {
    var firebaseObj = new Firebase("FireaseURL/");
    loginObj = $firebaseAuth(firebaseObj);
    $scope.user = {};
    var login = {};
    $scope.SignIn = function (e) {
        login.loading = true;
        e.preventDefault();
        var username = $scope.user.email;
        var password = $scope.user.password;
        loginObj.$authWithPassword({
            email: username,
            password: password
        })
            .then(function (user) {
                //Success callback
                // alert('Authentication successful');
                login.loading = false;
                $location.path('/dashboard/godash')
            }, function (error) {
                //Failure callback
                alert('Authentication failure');
            });
        }
    }])

my problem is that, when I refresh my login page by browser refresh, it refreshes successfully, but after login when refresh any page it gives me error 我的问题是,当我通过浏览器刷新来刷新登录页面时,它刷新成功,但是登录后刷新任何页面时却给了我错误

Page Not Found 网页未找到

my HTML: 我的HTML:

<!DOCTYPE html>
<html data-ng-app="sampleApp">
<head>
    <title>My new Project</title>
    <meta charset="utf-8" />
    <!-- AngularJS -->
    <script src="Scripts/angular.min.js"></script>
    <script src="Scripts/angular-route.min.js"></script>
    <!-- Firebase -->
    <script src="https://cdn.firebase.com/js/client/2.2.4/firebase.js"></script>
    <!-- AngularFire -->
    <script src="https://cdn.firebase.com/libs/angularfire/1.2.0/angularfire.min.js"></script>
    <script src="Scripts/App.js"></script>
    <base href="/" />
</head>
<body ng-view>

</body>
</html>

If you configure $location to use html5Mode (history.pushState), you need to specify the base URL for the application with a <base href=""> tag or configure $locationProvider to not require a base tag by passing a definition object with requireBase:false to $locationProvider.html5Mode() : 如果将$ location配置为使用html5Mode (history.pushState),则需要使用<base href="">标签为应用程序指定基本URL,或者通过将定义对象传递给$locationProvider以使其不需要基本标签对$locationProvider.html5Mode() requireBase:false

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

From : https://docs.angularjs.org/error/$location/nobase 来自: https : //docs.angularjs.org/error/$location/nobase

Be sure to check all relative links, images, scripts etc. Angular requires you to specify the url base in the head of your main html file () unless html5Mode.requireBase is set to false in the html5Mode definition object passed to $locationProvider.html5Mode(). 确保检查所有相对链接,图像,脚本等。Angular要求您在主html文件()的开头指定url基,除非在传递给$ locationProvider.html5Mode的html5Mode定义对象中将html5Mode.requireBase设置为false。 ()。 With that, relative urls will always be resolved to this base url, even if the initial url of the document was different. 这样,即使文档的初始URL不同,相对URL仍将始终解析为该基本URL。

From : https://code.angularjs.org/1.3.14/docs/guide/$location 来自: https : //code.angularjs.org/1.3.14/docs/guide/$location

Simple example: 简单的例子:

Index.html Index.html

<!DOCTYPE html>
<html data-ng-app="appMain">
<head>
    <meta charset="utf-8" />
      <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular.min.js"></script>
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular-route.js"></script>
      <script src="script.js"></script>
    <base href="/" />
</head>
<body ng-view>

</body>
</html>

script.js script.js

var appMainModule = angular.module('appMain', ['ngRoute'])
  .config(function($routeProvider, $locationProvider) {
    $routeProvider.when('/', {
      templateUrl: '/Templates/CustomerLogin.html',
      controller: 'HomeCtrl'
    });
    $routeProvider.when('/customer/home', {
      templateUrl: '/Templates/CustomerHome.html',
      controller: 'ForLogout'
    });
    $routeProvider.when('/dashboard/godash', {
      templateUrl: '/Templates/dashboard.html',
      controller: 'DashboardCtrl'
    });
    $routeProvider.otherwise({
      redirectTo: '/'
    });
    $locationProvider.html5Mode(true);
  });

appMainModule.controller('HomeCtrl', ['$scope', '$location', function($scope, $location) {
  $scope.godash = function(e) {
    $location.path('/dashboard/godash')
  }
}]);


appMainModule.controller('DashboardCtrl', ['$scope', '$location', function($scope, $location) {
  $scope.home = function(e) {
    $location.path('/customer/home')
  }
}]);

appMainModule.controller('ForLogout', ['$scope', '$location', function($scope, $location) {
  $scope.home = function(e) {
    $location.path('/')
  }
}]);

/Templates/CustomerLogin.html /Templates/CustomerLogin.html

<div>
<button ng-click="godash()">/dashboard/godash</button>
</div>

/Templates/CustomerHome.html /Templates/CustomerHome.html

<div>
<button ng-click="home()">/</button>
</div>

/Templates/dashboard.html /Templates/dashboard.html

<div>
<button ng-click="home()">/customer/home</button>
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM