2017-02-13 51 views
0

我有我的狀態設置定義如下空:

$stateProvider 
     .state('parentState', { 
     abstract: true, 
     url: '/:tenantId/', 
     param: { 
      tenantId: { 
      array: false 
      } 
     }, 
     views: { 
      '[email protected]': { 
      templateUrl: 'home/header.html', 
      controller: 'Header as vm' 
      }, 
      '[email protected]': { 
      templateUrl: 'home/footer.html', 
      controller: 'FooterCtrl as vm' 
      } 
     }, 
     resolve: userResolve, 
     data: { 
      private: true 
     } 
     }) 
     //...4-5 other child states, then a state to handle unknown urls 
     .state('parentState.otherwise', { 
     views: { 
      '@': { 
      templateUrl: 'home/404/pageNotFound.html', 
      controller: 'PageNotFoundCtrl as vm' 
      } 
     } 
     }); 
    $urlRouterProvider.otherwise(function ($injector) { 
     $injector.get('$state').go('parentState.otherwise', {}, { 
     location: false 
     }); 
    }); 

現在,輸入無效的URL時,parentState.otherwise狀態正確加載,並parentState PARAM,即tenantId ,也正確填寫。 然而,在頁面重載(刷新,按Ctrl + R)具有相同的無效的URL,parentState.otherwise狀態負荷,但問題是parentState PARAM,即tenantId即將爲空字符串(「」)。

+0

注:'PARAM:'應該是'PARAMS:' –

+0

嘗試過,但沒」不改變任何事情。行爲是一樣的。 – Avinash

回答

0

不知何故,在location: false的情況下,父狀態,即parentState在這種情況下,沒有從頁面刷新的URL中獲取tenantId參數。所以,如果我們明確地傳遞tenantId參數去子狀態,即parentState.otherwise而打開它,一切都完美的作品甚至在頁面刷新:

$urlRouterProvider.otherwise(function ($injector) { 
    $injector.get('$state').go('parentState.otherwise', { 
    tenantId: 'someTenantId' 
    }, { 
    location: false 
    }); 
});