[英]Angularjs Client-Side Routing with ui-router
我使用ui-router
(狀態)進行路由:
$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
,應用程序將刷新頁面。
請記住,我從鏈接中刪除了#。
為什么棱角分明不知道我的路線?
或者我如何設置角度的客戶端菜單?
Angular知道您的路線,但您的網絡服務器可能認為他需要在地圖posts
顯示index.html
頁面
嘗試將你的html5Mode設置為false,看看它是否仍然發生在這個鏈接上並查看關於Hashbang and HTML5 modes
的部分
尤其是最后一行requires server-side configuration: Yes
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.