[英]IIS URL rewrite module with angularJS does not work
I have a single page webapp where any request that begins with request for eg http://localhost/appname/request*
, the home page is sent back to the client using IIS URL rewrite module. 我有一个单页webapp,其中任何以请求开头的请求,例如
http://localhost/appname/request*
,主页都使用IIS URL重写模块发送回客户端。
When Angular receives the webpage, it sees the route. Angular收到网页后,便会看到路线。 I need to make sure Angular picksup up the routeParams.
我需要确保Angular拾取了routeParams。
Client request : http://localhost/appname/request/param1/param2
客户端请求:
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('!');
The controller listens to $routeChangeSuccess
. 控制器监听
$routeChangeSuccess
。
app.controller('MyCtrl',function($scope){
$scope.$on('$routeChangeSuccess',function(event,routeData,$timeout,$rootScope){
//routeData.pathParams are blank
});
});
Also the URL changes to home page. URL也更改为主页。 Ie I am redirected to
http://localhost/appname
. 即我被重定向到
http://localhost/appname
。
What I am doing wrong? 我做错了什么?
If I understand correctly, you want to get the route params but the correct way to do this is by injecting $routeParams into the controller: 如果我理解正确,则想获取路由参数,但是正确的方法是将$ routeParams注入控制器:
app.controller('MyCtrl',function($scope, $routeParams){
if($routeParams.param1){
alert('SUPER FLY!');
}
});
http://docs.angularjs.org/tutorial/step_07 http://docs.angularjs.org/tutorial/step_07
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.