2016-06-22 39 views
0

我試圖用html提供程序實現角度js狀態更改。但是當我嘗試刷新頁面時頁面顯示404錯誤。問題是什麼。 ?角度js頁面刷新不起作用

我的狀態提供商

$stateProvider 
    .state('home', { 
     url: '/Edu', 
     views: { 
      '[email protected]': { 
       templateUrl: 'dashboard.html', 
       controller: 'dashCtrl' 
      } 
     }, 
     params: {'registerData' : ''} 
    }) 
    .state('dash_home', { 
     url: '/dash_home', 
     views: { 
      '[email protected]': { 
       templateUrl: 'dash_home.html', 
       controller: 'dashCtrl' 
       } 
     }, 
     params: {'registerData' : ''} 
    }) 
    .state('login', { 
     url: '/login', 
     views: { 
      '[email protected]': { 
       templateUrl: 'login.html', 
       controller: 'dashCtrl' 
      } 
     }, 
     params: {'registerData' : ''} 
    }); 

HTML5的conf是,

app.config(function($locationProvider) { 
    $locationProvider.html5Mode(false); 
}); 

,也把

<base href="/"> 

在HTML頁面。但它沒有工作。

編輯

server { 
    listen 80 ; 
    listen [::]:80 ; 
    root /var/www/Edu; 

location/{ 
     # First attempt to serve request as file, then 
     # as directory, then fall back to displaying a 404. 
     root /var/www/Edu; 
     try_files $uri /index.html; 
    } 
} 
+0

你在瀏覽器中輸入的網址是什麼? –

+0

[重新加載頁面給AngularJS HTML5模式提供錯誤的GET請求](http://stackoverflow.com/questions/16569841/reloading-the-page-gives-wrong-get-request-with-angularjs-html5-模式) – Phil

+0

url:Log In jicks

回答

0

,你可以使用默認的重定向當URL是錯誤的或不存在的狀態(只是注入$ urlRouterProvider到配置功能)。

添加一個 '/' 狀態重定向到 '家庭' 頁面,如下所示:

.state('/', { 
     url: '/Edu', 
     views: { 
      '[email protected]': { 
       templateUrl: 'dashboard.html', 
       controller: 'dashCtrl' 
      } 
     }, 
     params: {'registerData' : ''} 
    }) 

添加默認重定向,像這樣:

$urlRouterProvider.otherwise('home'); 

希望這有助於好運。