【发布时间】:2016-01-31 14:14:57
【问题描述】:
状态路由不适合我。 如果我单击主页中的链接,第一个名为 home 的链接会自动加载,它应该转到 search 页面,而是将数据附加到主页本身。所以我在同一页面中同时看到主页和搜索页面数据。
index.html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<script src="lib/ionic/js/ionic.bundle.js"></script>
<script src="js/index.js"></script>
<!--<base href="/">-->
</head>
<body ng-app="hello">
<ion-nav-view></ion-nav-view>
</body>
</html>
index.js
angular.module('hello', ['ionic'])
.config(function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('home');
$stateProvider.state('home', {
url: "/home",
templateUrl: "/home.html"
});
$stateProvider.state('search', {
url: "/search",
templateUrl: "/search.html"
});
});
home.html
<a href="#/search">Go to Search</a>
搜索.html
<div> you are in Search Screen</div>
我创建了一个 Plunker ,但由于某种原因我没有看到任何输出 http://plnkr.co/edit/UpnS01Oy2MLqHvKSAPST
【问题讨论】:
-
点击链接时控制台出现错误?您是否尝试过使用 ui-sref 属性?喜欢
ui-sref="search"
标签: angularjs ionic-framework angular-ui-router