optional parameter in flatiron/director

678 Views Asked by At

Is it possibile create a route with optional parameter in flatiron/director?

var router = Router({

    'order' : function(){
        // create a order
    },

    'order/:orderId' : function(orderId){
        // load order by id
    }
}).init();

Can I use one single route to manage the edit/load order?

1

There are 1 best solutions below

0
Pete Cook On BEST ANSWER

From director docs:

var router = Router({
  //
  // given the route '/hello/world/johny/appleseed'.
  //
  '/hello': {
    '/world/?([^\/]*)\/([^\/]*)/?': function (a, b) {
      console.log(a, b);
    }
  }
});

Basically use regex instead of simple :tokens

johny and appleseed become optional parameters.