【问题标题】:Ionic angular state routing not working properly离子角状态路由无法正常工作
【发布时间】: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


【解决方案1】:

您的代码中存在问题:视图必须包含在 &lt;ion-view&gt; 元素中。

<ion-view view-title="Home">
  <ion-content>
    <a href="#/search">Go to Search</a>
  </ion-content>
</ion-view>

这是带有更正的 Plunker:

http://plnkr.co/edit/ONAIfq26uwN7ZoYQtY0N?p=preview

PS:在 Ionic 构建之前注意添加对 cordova.js 的引用。

【讨论】:

  • 感谢您的 Plunker 作品完美,让我将其放入我的代码中
猜你喜欢
  • 2017-10-20
  • 2016-10-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-03-18
相关资源
最近更新 更多