2

I am using angularjs router, as the application development is almost done, I cant use UI-router. Recently I implemented two optional parameter in route by following this answer. Here is what I did.

app.when('/someUrl/:param1?/:param2?',{
   templateUrl:'templateurl',
   controller:'controllerName'
});

But when I use $location.path('/someUrl/1234/5678');, the url is adding equivalent hex code of '?' in URL either parameter is available or not.

I am not sure why this parameter is coming even if I am sending parameter. the url is looking like

localhost/someurl/1234%3F/5638%3F

How can avoid this %3F and keep optional routing functionality without using duplicate route definitions.

**Sorry for typo mistake, I already defined routes with :, that is not problem with :.

Community
  • 1
  • 1
Laxmikant Dange
  • 7,606
  • 6
  • 40
  • 65

1 Answers1

3

%3F is ?, Since you have not provided the : its treated as part of URL thus they are encoded.

You need to use : to define parameter.

app.when('/someUrl/:param1?/:param2?',{
   templateUrl:'templateurl',
   controller:'controllerName'
});
Satpal
  • 132,252
  • 13
  • 159
  • 168