【发布时间】:2015-08-15 18:18:39
【问题描述】:
我正在尝试让我的嵌套状态工作,但我不知道我做错了什么。
Here is my simple example on plunkr
主体:
<div class="site_container" ui-view></div>
我想在此处显示我的站点容器,它应该始终显示:
<header class="main_header">
<h1>My header</h1>
</header>
<main ui-view></main>
在-tag中我想在一些子状态之间切换,举个简单的例子我只想显示一个:
<h2>My content</h2>
因此,我想要:
<div class="site_container" ui-view>
<header class="main_header">
<h1>My header</h1>
</header>
<main ui-view>
<h2>My content</h2>
</main>
</div>
这是我的配置:
angular.module('myApp').config([
'$stateProvider',
'$urlRouterProvider',
function (
$stateProvider,
$urlRouterProvider
) {
$stateProvider
.state('main', {
abstract: true,
url: '/',
templateUrl: 'app.html'
})
.state('main.child', {
url: '/child',
templateUrl: 'child.html',
})
// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise('/child');
}]);
你能告诉我,我做错了什么吗?
【问题讨论】:
-
可能是因为你想使用HTML5的路由,此时需要添加
$locationProvider.html5Mode(true); -
谢谢,但这会使我所有的相对路径崩溃:-(
标签: javascript angularjs routing angular-ui-router angularjs-routing