带有angularJS的IIS URL重写模块不工作
我有一个单页webapp,其中任何请求都以请求开始,例如带有angularJS的IIS URL重写模块不工作,angularjs,angularjs-routing,Angularjs,Angularjs Routing,我有一个单页webapp,其中任何请求都以请求开始,例如http://localhost/appname/request*,使用IIS URL重写模块将主页发送回客户端 当Angular收到网页时,它会看到路由。我需要确认一下路线图 客户端请求:http://localhost/appname/request/param1/param2 $routeProvider.when('/request/:param1/:param2',{ templateUrl : 'app/views/my
http://localhost/appname/request*
,使用IIS URL重写模块将主页发送回客户端
当Angular收到网页时,它会看到路由。我需要确认一下路线图
客户端请求: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
});
});
URL也会更改为主页。即,我被重定向到http://localhost/appname
我做错了什么?如果我理解正确,您希望获取路由参数,但正确的方法是将$routeParams注入控制器:
app.controller('MyCtrl',function($scope, $routeParams){
if($routeParams.param1){
alert('SUPER FLY!');
}
});
如果您正在尝试使用HTML5模式,请查看:谢谢。我被重定向的原因是因为
否则
规则。我并没有做任何改变,但它现在起作用了。此外,我不必将$routeParams
与$scope
一起传递。我在('$routeChangeSuccess',函数(event,routeData){})上使用了$scope.$on代码>在myMyctrl
中。