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

1 Answer 1

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'
});
Sign up to request clarification or add additional context in comments.

5 Comments

this is not the problem with ':'. I updated my question, by mistake, I forget to mention ':' here in question. Colon is not the problem.
It is taking the parameters but with '?', I can access parameters with param variable, and the value is included with '?' character
@LaxmikantDange, Which version of Angular you are using?
@LaxmikantDange, There should not be any problem
yes there is, is adding extra '?' character as mentioned in optional parameter declaration. if I doesnt pass any parameter then also it is including '?' as parameter

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.