【发布时间】:2014-07-26 09:14:03
【问题描述】:
我的 ui-router 状态提供程序中有以下状态:
$urlRouterProvider.when('/parent', '/parent/child');
$stateProvider.state('parent', {
url: "/parent",
abstract: true
});
$stateProvider.state('parent.child', {
url: "/child"
});
遵循 ui-router 文档中here 中解释的默认子状态的最佳实践。
但是,当我现在在我的文档中包含一个链接时,在某处使用ui-sref 引用父级,例如<a ui-sref="parent">Link</a>,我总是收到一个错误,说我无法转换到抽象状态。当我在地址栏中手动输入 URL 并按 Enter 时,一切正常。
相关Plunker:http://plnkr.co/edit/d3Z0tOwC3VCTPqGiB0df?p=preview
如何将ui-sref 与默认子状态结合起来?
【问题讨论】:
-
所有抽象状态都要求您提供具有值
<ui-view/>的template属性,因为子模板/Url 插入它。现在,如果您按照@Chris-Preston 的建议使用<a ui-sref="parent.child">创建了一个href,那么您的网址栏将加载/#/parent/child。这帮助了我,link。至少如果我理解正确的话。如果我错了,请告诉我:S
标签: angularjs angular-ui angular-ui-router