Laxmikant Dange
Laxmikant Dange

Reputation: 7688

Extra character while using multiple optional parameter in angular route

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

Upvotes: 2

Views: 169

Answers (1)

Satpal
Satpal

Reputation: 133403

%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'
});

Upvotes: 3

Related Questions