2016-08-13 3 views
0

Szenario ist,AngularFire Browser Refresh gibt Fehler Seite nicht gefunden

Im neu zu AngularJS und sie ein AngularJS mit AngularFire, ich habe meine Routing-bye mit $routeProvider definiert, siehe unten

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); 
}); 

das ist mein 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'); 
      }); 
     } 
    }]) 

mein Problem ist, dass, wenn ich meine Login-Seite durch Aktualisierung des Browsers zu aktualisieren, es erfolgreich aktualisiert, aber nach der Anmeldung, wenn aktualisiert beliebige Seite es Nicht gefunden

mein HTML gibt mir

Seite Fehler:

<!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> 

Antwort

0

Wenn Sie konfigurieren $ Standort html5Mode (history.pushState) zu verwenden, müssen Sie die Basis-URL angeben, für die Anwendung mit einem <base href=""> Tag oder konfigurieren Sie $locationProvider so, dass kein Basis-Tag erforderlich ist, indem ein Definitionsobjekt mit requireBase:false an $locationProvider.html5Mode():

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

Von: https://docs.angularjs.org/error/$location/nobase

Seien Sie sicher, alle relativen Links, Bilder zu überprüfen, Skripte usw. Angular Sie die URL Basis in den Kopf Ihrer Haupt-HTML-Datei(), es sei denn html5Mode.requireBase angeben erfordert im Definitionsobjekt html5Mode, das an $ locationProvider.html5Mode() übergeben wird, auf false gesetzt. Damit werden relative URLs immer in diese Basis-URL aufgelöst, auch wenn die ursprüngliche URL des Dokuments anders ist.

Von: https://code.angularjs.org/1.3.14/docs/guide/$location

Einfaches Beispiel:

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

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

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

/Templates/CustomerHome.html

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

/Templates/dashboard.html

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

'requireBase: false' Arbeits –

+0

nicht Lesen Sie mehr über' requireBase: false' von https: //code.angularjs.org/1.3.14/docs/guide/$location, ich hatte mehr Details in der Antwort aktualisiert. – sreeramu

+0

http: //webdesign.tutsplus.com/articles/quick-tip-set-relative-URLs-mit-der-Basis-Tag - cms-21399 von diesem Beitrag, ich denke, ich brauche URL umschreibt, Basis-Tag wird keine Lösung –