Router
Description
Section titled “Description”The Router module routes the data flow to different modules based on the value of a specific field or the evaluation of conditions. It first evaluates the configured field (for example data.type) and looks for an exact match in the defined routes. If there is no exact match, it attempts to evaluate each route key as a JavaScript expression. If no route matches, it redirects to the defaultPath. It is useful for directing the flow to different branches based on data type, category, or any dynamic value.
Configuration
Section titled “Configuration”Parameters
Section titled “Parameters”| Parameter | Type | Required | Description |
|---|---|---|---|
| field | text | Yes | JavaScript expression that is evaluated to obtain the value to compare. E.g.: data.type, data.status. |
| routes | text (JSON) | Yes | JSON object where keys are values or conditions to compare, and values are the destination module names. E.g.: {"value1": "module_A", "value2": "module_B"}. |
| defaultPath | text | No | Name of the module to redirect to if no route matches. |
Output
Section titled “Output”{ "nextModule": "modulo_destino", "data": { "datos_originales": "sin_modificar" }, "_meta_": { "routerField": "valor_evaluado", "routerPath": "modulo_destino", "routerDefault": false }}Usage Example
Section titled “Usage Example”Basic case
Section titled “Basic case”{ "label": "Router", "field": "data.tipo", "routes": "{\"factura\": \"procesarFactura\", \"pedido\": \"procesarPedido\", \"devolucion\": \"procesarDevolucion\"}", "defaultPath": "procesoGenerico"}- The
fieldvalue is evaluated witheval(), so it can be any valid JavaScript expression (e.g.:data.type,data.items.length). - Routes are first compared by exact match with the field value.
- If there is no exact match, each route key is evaluated as a boolean JavaScript expression.
- If
routesis a string, it is automatically parsed as JSON. - Data passes without modification to the next node; the Router does not transform data.
- The
_meta_includes information about the selected route and whether the defaultPath was used.