我使用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>
更新我的视图。当我在第一次下载后使用地址栏将网址更改为localhost:port/Posts
时,应用会刷新页面。
请注意,我从链接中删除了#。
为什么棱角分明不知道我的路线?
或者我如何设置角度的客户端菜单?
答案 0 :(得分:1)
Angular知道您的路线,但您的网络服务器可能认为他需要在地图中显示index.html
页面posts
尝试将html5Mode设置为false并查看是否仍然发生
this link并查看有关Hashbang and HTML5 modes
,尤其是最后一行requires server-side configuration: Yes