2013-10-02 43 views
0

我有一个单独的页面web应用程序,其中的任何请求以请求开始,例如, http://localhost/appname/request*,使用IIS URL重写模块将主页发送回客户端。带有angularJS的IIS URL重写模块不起作用

当Angular收到网页时,它会看到路线。我需要确保Angular拾取routeParams。

客户端请求:http://localhost/appname/request/param1/param2

$routeProvider.when('/request/:param1/:param2',{ 
    templateUrl : 'app/views/myView.html', 
    controller : 'MyCtrl', 
    caseInsensitiveMatch : true 
}); 
$routeProvider.otherwise({ redirectTo: '/' , caseInsensitiveMatch : true });  

$locationProvider.html5Mode(true).hashPrefix('!'); 

控制器监听$routeChangeSuccess

app.controller('MyCtrl',function($scope){ 
    $scope.$on('$routeChangeSuccess',function(event,routeData,$timeout,$rootScope){ 
    //routeData.pathParams are blank  
    });  
}); 

此外,网址更改为主页。即我被重定向到http://localhost/appname

我做错了什么?

回答

1

如果我理解正确的话,你想要得到的路线PARAMS但要做到这一点,正确的做法是通过注入$ routeParams到控制器:

app.controller('MyCtrl',function($scope, $routeParams){ 
    if($routeParams.param1){ 
     alert('SUPER FLY!'); 
    } 

}); 

http://docs.angularjs.org/tutorial/step_07

+0

HTTP://docs.angularjs .org/tutorial/step_07 –

+0

如果您尝试使用html 5模式,请查看:http://stackoverflow.com/questions/16677528/location-switching-between-html5-and-hashbang-mode-link-rewriting –

+0

谢谢。我被重定向的原因是因为'否则'规则。我没有真正做出任何改变,但现在正在工作。此外,我不必传递'$ routeParams'以及'$ scope'。我使用'$ scope。$ on('$ routeChangeSuccess',function(event,routeData){});'在我的'Myctrl'里面。 – lostpacket