0
votes

The state routing is not working well for me. The first link called home loads automatically if I click the link in home page it should go to search page but instead it appends the data to the home page itself. so I see both home and search page data in same page.

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>

search.html

<div> you are in Search Screen</div>

I have created a Plunker , but for some reason I don't see any output http://plnkr.co/edit/UpnS01Oy2MLqHvKSAPST

1
Any errors in console when you click on the link? Did you try with ui-sref attribute? Like ui-sref="search" - BotanMan

1 Answers

0
votes

There was an issue in your code: the view must be wrapped in <ion-view> element.

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

Here is the Plunker with corrections:

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

PS: pay attention before Ionic build add reference to cordova.js.