2

我正在用離子建立一個移動應用程序,我面臨着一個奇怪的問題.. 如果我重新加載頁面(F5),比如說「/ tabs/connected/channel /編輯「我總是重定向到」/ tabs/home「(解決狀態之後)。離子框架重定向到家開始

PS:解決階段正確執行,我從不拒絕它。然後承諾解決我總是重定向到/ tabs/home。

這裏是我的配置塊:

.config(function($stateProvider, $urlRouterProvider) { 
var userResolve = function(user, $q, $auth) { 

     if (!$auth.isAuthenticated()) { 
      return $q.resolve(); 
     } 
     if (user.loaded) { 
      return $q.resolve(); 
     } 
     return user.blockingRefresh(); 
    }; 

    // 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 

    // setup an abstract state for the tabs directive 
     .state('tabs', { 
      url: '/tabs', 
      abstract: true, 
      templateUrl: 'templates/tabs.html' 
     }) 
     .state('tabs.home', { 
      url: '/home', 
      views: { 
       'home-tab': { 
        templateUrl: 'templates/home.html', 
        controller: '' 
       } 
      } 
     }) 
     .state('tabs.account', { 
      url: '/account', 
      views: { 
       'account-tab': { 
        templateUrl: 'templates/account/account.html', 
        controller: 'AccountController' 
       } 
      }, 
      resolve: { 
       userData: userResolve 
      } 
     }) 
     .state('tabs.login', { 
      url: '/account/login', 
      views: { 
       'account-tab': { 
        templateUrl: 'templates/account/login.html', 
        controller: 'AccountController' 
       } 
      } 
     }) 
     .state('tabs.register', { 
      url: '/account/register', 
      views: { 
       'account-tab': { 
        templateUrl: 'templates/account/register.html', 
        controller: 'RegisterController' 
       } 
      } 
     }) 
     .state('tabs.connected', { 
      url: '/connected', 
      abstract: true, 
      views: { 
       'account-tab': { 
        templateUrl: "templates/connected.html" 
       } 
      }, 
      resolve: { 
       userData: userResolve 
      } 
     }) 
     .state('tabs.connected.channel-create', { 
      url: '/channel/create', 
      templateUrl: 'templates/channel/create.html', 
      controller: 'CreateChannelController' 
     }) 
     .state('tabs.connected.channel-edit', { 
      url: '/channel/edit', 
      templateUrl: 'templates/channel/edit.html', 
      controller: 'EditChannelController' 
     }); 



    // if none of the above states are matched, use this as the fallback 
    $urlRouterProvider.otherwise('/tabs/account'); 

}) 

這裏是tabs.html:

<ion-tabs class="tabs-assertive tabs-icon-top"> 

<ion-tab title="Home" ui-sref="tabs.home" icon-on="ion-ios-filing" icon-off="ion-ios-filing-outline"> 
    <ion-nav-view name="home-tab"></ion-nav-view> 
</ion-tab> 

<ion-tab title="Account" ui-sref="tabs.account" icon-on="ion-ios-gear" icon-off="ion-ios-gear-outline"> 
    <ion-nav-view name="account-tab"></ion-nav-view> 
</ion-tab> 

我必須精確,以至於我從來沒有使用$狀態.go('/ tabs/home')我是我的代碼。我確信這一點。 即使我重新加載應用程序,我的目標是保持相同的路線。 (這個問題在某些州不會發生,我不知道爲什麼,因爲他們沒有做任何不同於有問題的事情。)

謝謝!

回答

0

我也在Angular Ui-Router中遇到這種類型的錯誤。

下面的解決方案是我的工作。

只要改變它太

.state('tabs.connected.channelcreate', { 
     url: '/channelcreate', 
     templateUrl: 'templates/channel/create.html', 
     controller: 'CreateChannelController' 
    }) 

網址應該是

"/tabs/connected/channeledit" 

,它會工作。

+0

謝謝你,但我沒有工作...我有這樣的: '.STATE( 'tabs.connected.channelcreate',{ 網址: '/ channelcreate', templateUrl:「模板/渠道/ create.html上」, 控制器: 'CreateChannelController' }) .STATE( 'tabs.connected.channeledit',{ URL: '/ channeledit', templateUrl: '模板/信道/ edit.html', 控制器:'EditChannelController' });' – NathanVss

+0

@NathanVss:你可以發佈**模板/ tabs.html **代碼片段,以便我可以看看並幫助你。 – ProCylon

+0

感謝您的幫助!我剛剛編輯了我的問題。 – NathanVss