3

我用ui-router(州)爲我的路由:Angularjs客戶端路由與UI路由器

$urlRouterProvider.otherwise('/Home'); 

$stateProvider 
    .state('home', { 
     url: '/Home', 
     templateUrl: '/Home/Home', 
     controller: 'MainCtrl' 
    }) 
    .state('posts', { 
     url: '/Posts', 
     templateUrl: '/Home/Posts', 
     controller: 'PostCtrl' 
    }); 

$locationProvider.html5Mode(true); 

HTML我有這樣的事情:

<html> 

<head> 
    <base href="/" /> 
    <!--render scripts --> 
    <title>My Angular App!</title> 
</head> 

<body ng-app="flapperNews" ngcloak> 
    <div class="row"> 
     <div class="col-md-6 col-md-offset-3"> 
      <ul> 
       <li><a ui-sref="home">Home</a></li> 
       <li><a ui-sref="posts">Posts</a></li> 
      </ul> 
      <ui-view></ui-view> 
     </div> 
    </div> 
</body> 
</html> 

當我用我的菜單鏈接(主頁,帖子)該應用程序工作正常,並根據需要更新我的觀點<ui-view></ui-view>。當我第一次下載後使用地址欄將url更改爲localhost:port/Posts時,該應用會刷新頁面。

請記住,我已將#從鏈接中刪除。

爲什麼角度不知道我的路線?

或者我該如何設置角度的客戶端菜單?

+0

@PankajParkar,我試過了,菜單既一些變體效果很好。 我的地址欄導航問題。 – Dmitry

回答

1

角知道你的路線,但你的Web服務器可能以爲自己需要顯示index.html頁面在地圖posts

嘗試將html5Mode設置爲false,看看它是否仍然發生 的this link,並期待在部分約Hashbang and HTML5 modes

,尤其是最後一排requires server-side configuration: Yes

+0

嘗試使用'#'路線? – Dmitry

+0

是的,並使用hashbang方法。如果這不是你想要的,你需要在你的網絡服務器上做些什麼來確保它不會返回404或其他東西 –