简体   繁体   中英

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.

When Angular receives the webpage, it sees the route. I need to make sure Angular picksup up the routeParams.

Client request : 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 .

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

Also the URL changes to home page. Ie I am redirected to 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:

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

});

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM