2015-12-30 108 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; 
     } 
相关问题