I am trying to create a basic router that can match optional parameters.
Consider the following code:
routes: { '/jobs' : 'jobs', '/jobs/p:page' : 'jobs', '/jobs/job/:job_id' : 'jobs', '/jobs/p:page/job/:job_id' : 'jobs' } jobs: function(page, job_id){
If I go to the abc.com/ # / jobs / p104 / URL , the page parameter will be 104 . However, if you go to abc.com/ # / jobs / job / 93 , the job_id parameter is undefined , but page 93 .
Thus, the underlying router basically matches the hash route parameters in order, not by name.
I know that the solution would be to use * splat and split the parameters with the regex, but I can't get the regex part to work (my regex is pretty rusty). Can anybody help?
If there is a better solution than using * splat, can anyone share it?
peter
source share