2015-12-30 30 views
0

我有一些問題,一個頁面重定向到另一個
我用控制器重定向一個網頁到另一個

$window.location.href = '/test'; 
$location.path("/test"); 

代碼,但是當我使用它,它會主頁上重定向

.state('test', { 
    url: '/tests/:testId', 
    templateUrl: TEMPLATE_URL + 'tests/test.html', 
    controller: "testController", 
    resolve: { 
     testId: ['$stateParams', function ($stateParams) { 
      return $stateParams.testId; 
     }] 
    }, 
    data: { 
     title: "Test" 
    } 
    }); 

我想在上面的頁面上重定向。 我已經在控制器中創建了一個函數,並調用了表格行的點擊。但是當我點擊行時,這個重定向到我的主頁。

+0

哪裏是/路徑的狀態? –

回答

1

只有一個州,名稱爲test,網址爲/test/:testId。既然你明明使用ui-router,與各國合作,執行以下代碼應該做的伎倆:

$state.go('test', {'testId': 123}); 

不要忘記注入$state到控制器中的這一點。

如果你想使用一種「硬編碼」 URL重定向($location.path$window.location.href是直接網址重定向)的代碼是這樣的:

$window.location.href = '/test/123'; 
$location.path("/test/123"); 

你忘了參數你的榜樣。

+0

這是行不通的,我用它$ state.go('test',{'testId':123});但它也重定向主頁。 –

+0

@VipinJain然後請將您的控制器的完整代碼發佈到您的問題。 –

+0

好吧,我正在嘗試做這個。我不能發佈實際的代碼。但如果我不能我將definetly發送。 –

1

你的情況,你必須使用:

$state.go('test', { testId : 'yourTestId' }, {reload: true}); 

$state.go('test'); //For a route without params 

確保你在你的控制器注入$狀態。

如果你想使用

$window.location.href = '/plan'; 
$location.path("/plan"); 

你必須配置你的Web服務器,accepte此:

爲例nginx的:

location/{ 
       ##try_files $uri$args $uri$args/ $uri/ /index.html$args =404; 
       try_files $uri $uri/ /index.html =404; 
     } 
相關問題