$ state.go将我带到原本声明中,并且不会过渡到正确的状态



我正在尝试进入菜单。home状态,但是当我做$state.go('menu.home)时,它无能为力,并且会进入其他语句。不知道我在做什么错。

controller.js

$state.go('menu.home');

utaes.js

angular.module('app.routes', [])    
  .config(function($stateProvider, $urlRouterProvider) {

// Ionic uses AngularUI Router which uses the concept of states
  // Learn more here: https://github.com/angular-ui/ui-router
  // Set up the various states which the app can be in.
  // Each state's controller can be found in controllers.js
  $stateProvider
  .state('login', {
     cache: false,
     url:'/login',
     templateUrl: 'templates/login.html',
     controller: 'LoginCtrl'
  })  
  .state('menu.home', {
     cache: false,
     url: '/home',
     views: {
       'side-menu21': {
         templateUrl: 'templates/home.html',
         controller: 'MapCtrl' //'homeCtrl'
       }
     }
  })
  .state('menu.cart', {
     url: '/page2',
     views: {
       'side-menu21': {
         templateUrl: 'templates/cart.html',
         controller: 'cartCtrl'
       }
     }
  })
  .state('menu.cloud', {
     url: '/page3',
     views: {
       'side-menu21': {
          templateUrl: 'templates/cloud.html',
          controller: 'cloudCtrl'
        }
     }
  })
  .state('menu.test', {
    cache: false,
    url: '/test',
    views: {
      'side-menu21': {
        templateUrl: 'templates/test.html',
        controller: 'testCtrl'
      }
    }
  })
  .state('menu', {
    url: '/side-menu21',
    templateUrl: 'templates/menu.html',
    abstract: true
  })
//$urlRouterProvider.otherwise('/login')
$urlRouterProvider.otherwise(function($injector, $location) {
  console.log("Could not find: " + JSON.stringify($location));
  $location.path('/login');
})

});

每次我尝试进行$state.go('menu.home')时,这是我得到的输出:

 Could not find:     {"$$protocol":"http","$$host":"localhost","$$port":8100,"$$path":"/app/sear    ch","$$search":    {},"$$hash":"","$$url":"/app/search","$$absUrl":"http://localhost:8100/#/ap   p/search","$$state":null,"$$replace":false}

login.html

     <ion-view view-title="Login" id="login" name="login-view">
       <ion-content class="padding">
    <!--##########################Facebook Login#################################-->
    <div class="facebookLogin">
    <a class="facebook-sign-in button button-royal" ng-click="facebookSignIn()">Login with Facebook</a>
    </div>
    <!--#######################END Facebook Login#################################-->
          <div class="list list-inset">
              <label class="item item-input">
                  <input type="text" placeholder="Username" ng-model="data.username">
              </label>
              <
    label class="item item-input">
                  <input type="password" placeholder="Password" ng-model="data.password">
              </label>
          </div>
      <button class="button button-block button-calm" ng-click="login()">Login</button>

  </ion-content>
</ion-view>

home.html

    <ion-view title="Test" id="home" class=" ">
    <ion-content padding="true" class="has-header"></ion-content>
<body ng-app="app" ng-controller="MapCtrl">
    <!-- Google Maps -->
    <link href="css/style.css" rel="stylesheet">
    <ion-content scroll="false">
        <div id="map-canvas"></div>
        <!-- END GOOGLE MAPS!-->
     <!-- Test button 
    <div class="TestButton">
    <div class="button button-assertive" ng-click="Test()" ng-hide="hideTestButton">
      <a class="button">Test</a>
    </div>
    </div>

    End Request Test button----------->

<!-- OS/Production selection footer-->
      <ion-tabs class="tabs-icon-top">
      <ion-tab title="Apple" icon-off="ion-social-apple" icon-on="ion-social-apple" href="#/app/search" on-select="appleTab()">
        <ion-nav-view name="tab-search"></ion-nav-view>
      </ion-tab>
      <ion-tab title="Windows" icon-off="ion-social-windows" icon-on="ion-social-windows" href="#/app/browse" on-select="windowsTab()">
        <ion-nav-view name="tab-browse"></ion-nav-view>
      </ion-tab>
      <ion-tab title="Mobile" icon-off="ion-iphone" icon-on="ion-iphone" href="#/app/playlists" on-select="mobileTab()">
        <ion-nav-view name="tab-playlists"></ion-nav-view>
      </ion-tab>
      <ion-tab title="Network" icon-off="ion-wifi" icon-on="ion-wifi"" href="#/app/playlists" on-select="otherTab()">
        <ion-nav-view name="tab-playlists"></ion-nav-view>
      </ion-tab>
    </ion-tabs>
</ion-content>
</body>
</ion-view>

如果我发表评论:$location.path('/login');,则可以使用。不知道为什么会发生这种情况,请帮助!

是您的控制器文件中的所有内容吗?也许其中有些东西阻止了达到这种状态。确保在主HTML文件中您拥有<main ui-view></main>来建立所有路线。

得到它,因此它不喜欢我在home.html中的离子标记中的href。它可能正在尝试解决它们,而不是指向有效URL。一旦我删除了HREF,效果很好。感谢所有人的帮助!

最新更新