how to specify optional parameter for rendrjs router

61 views Asked by At

I went through the documentation of the router of rendrjs and there is no mention of an optional parameter, and although they are saying, it's build very similar to the backbone router, it doesn't understand () as optional parameter...

so, does anyone here know what might be the way, or a work around it?

thanks in advance

2

There are 2 answers

0
Olena Horal On

I dont know about rendrjs but in Backbone you can define multiple routes in your router like that

var Router  = Backbone.Router.extend({
    initialize: function () {...},
         routes: {
               'videos/': 'videoFn',
               'videos/item:item/': 'videoFn',
                ...
        }
    })

and than in your videoFn check if your param is defined

function videoFn(item) {
    if (item!==undefined) {
       //do stuff
    }
}
0
bigethan On

If you have a more specific example of what you're trying to do it would be helpful.

In our Rendr app, we used regex routes for things that required any routing complexity. The regex routes will let you do pretty much anything (at the cost of some sanity). It'd let you put both options into a single route and then decide what to do in the controller with the params that come in.