Reputation: 791
Could somebody help me with routing rules configuration, please? I got problem with route optional parameters constraints.
the route named 'offerRegionCategoryTitle' should be invoked for /{region}/{category}/{title}/:page: url pattern - and this works properly,
but when I try to invoke /{region}/{category}/:page: url (etc. /pomorskie/programowanie/1) then the 'offerRegionCategoryTitle' route is handled.
I think that the problem is in route rules configuration. Could somebody help me please?
Source code: AppRouting: http://jsfiddle.net/kppfP/
Upvotes: 1
Views: 1553
Reputation: 1256
The problem is that both routes essentially match the "same" strings. You have 3 dynamic segments ({region}/{category}/:page:
or {region}/{category}/{title}
) and there is not enough info for the router to distinguish between both. If :page:
is always numeric and {title}
isn't you can add more rules to make sure it doesn't match the wrong route:
var catRoute = crossroads.addRoute('/{region}/{category}/:page:');
catRoute.rules = {
page : /^\d+$/ // should be numeric
};
var titleRoute = crossroads.addRoute('/{region}/{category}/{title}/:page:');
titleRoute.rules = {
title : function(val){
return isNaN(val); // title can't be numeric (should contain at least one char)
},
page : /^\d+$/ // should be numeric
};
See documentation about Route.rules and examples page for more info.
Upvotes: 2