[Coldbox-5+]: Module routing

I have a function in my main Router.cfc that simply loops through an array of values and adds a bunch of “utility” routes. I’d like to move this functionality to a module so that it’s easy to just drop it into any project and have it just work.

However, any routing struct I add in a module is relative to the module entry point and these routes would all be “top level” (not sure of the correct term?) Effectively, I’d like its routes to be added to the main routing table as if they were being added in the main app’s Router.cfc.

I tried making the module entry point “/” or the mapped app route, or left it blank, etc. but that’s doesn’t work.

So I then tried injecting the main router into my ModuleConfig.cfc and using it to add the routes rather than using the provided “Router” and that seems to get me partially there (though I’m not sure it’s the proper way to do this…)

property name="globalRouter" inject="router@coldbox";

When I add the routes using this injected router, the routes seems to be added as “top level” routes but they seem to get added in an incorrect order and so do not fire as intended. I’ve tried various combinations of append()/prepend(), injecting the router through the provider dsl, etc. but no love there…

Am I overlooking something obvious or is what I am trying not even possible?

Yes it is possible. IN ColdBox 5 we introduced the appRouter object. All ModuleConfigs receive it and that is the global router you can use for any global routing needs.

All documented here now: https://coldbox.ortusbooks.com/hmvc/modules/url-routing

Thank you, Luis. I switched to using the provided appRouter to add these top-level routes to the app from the module and so that saves me from injecting it, but I’m still bumping up against what I assume is the ordering of the routes?

If it would help to illustrate, here’s the relevant part of ModuleCOnfig.cfc:


function configure(){
settings = {
arrImplictEvents = [

function onLoad(){

// Assumes an ‘invalidEventHandler’ is set in Coldbox.cfc
function blockColdboxImplicitEvents(){
var configStruct = controller.getConfigSettings();
var invEvtHandler = configStruct[‘invalidEventHandler’];
var eventsInUse = settings.arrImplictEvents
.filter( (event) => len(configStruct[event]))
.each( (event) => appRouter.route( configStruct[event], invEvtHandler, event ) );


This just prevents someone from hitting these Coldbox events directly. When I put this in the app’s Router.cfc it works as expected, but when added via a module, I cannot get the main.invalidEvent to fire?