我正在尝试使用 AngularJS 构建网站,为此我使用了 Ui-router 扩展。我想问的是“主页”按钮应该如何配置?
HTML:
<body>
<a href="#">Home Page</a>
<div ui-view>
<div>
<a ui-sref="A">State A</a>
<a ui-sref="B">State B</a>
</div>
</div>
Javascript:index.html 没有状态。有必要吗?
.$state('A', {
url:"/A",
templateUrl:"A.html",
controller:"aController"
})
.$state('B', {
url:"/B",
templateUrl:"B.html",
controller:"bController"
})
最佳答案
你需要创建一个默认路由
// For any unmatched url, redirect to / (aka default)
$urlRouterProvider.otherwise("/");
// other routes
....
.$state('default', {
url:"/",
templateUrl:"default.html",
controller: ""
})
根据您的 html,一旦 UI-router 替换了 UI View 中的内容,2 个链接就会消失,您将需要一个包含这些链接的模板。
index.html
<body>
<a href="#">Home Page</a>
<div ui-view> <!-- The contents of this div are replaced with the states template -->
</div>
</body>
默认.html
<div>
<a ui-sref="A">State A</a>
<a ui-sref="B">State B</a>
</div>
关于javascript - ui-router返回主页按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33186714/