0

I have a single page webapp where any request that begins with request for e.g. 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. I.e. I am redirected to http://localhost/appname.

What I am doing wrong?

lostpacket
  • 1,383
  • 8
  • 26
  • 38

1 Answers1

1

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

Erstad.Stephen
  • 1,035
  • 7
  • 9
  • If you are tryinng to use html 5 mode, check this out: http://stackoverflow.com/questions/16677528/location-switching-between-html5-and-hashbang-mode-link-rewriting – Erstad.Stephen Oct 03 '13 at 02:26
  • Thanks. The reason I was redirected was because of the `otherwise` rule. I haven't really made any changes but its working now. Also I didn't have to pass `$routeParams` along with `$scope`. I used `$scope.$on('$routeChangeSuccess', function(event, routeData){});` inside my `Myctrl`. – lostpacket Oct 03 '13 at 12:14