bettercap/bettercap · error

Root segment cannot have matrix parameters

Error message

Root segment cannot have matrix parameters

What it means

When building navigation commands, the first command of an absolute navigation may not carry matrix parameters, because matrix params attach to segments and the root segment has none. This throw is the guard in the Navigation constructor rejecting commands like [{foo:'bar'}, '/path'] passed to router.navigate with absolute positioning.

Source

Thrown at modules/ui/ui/vendor.js:76718

function replaceSegment(current, oldSegment, newSegment) {
    var children = {};
    forEach(current.children, function (c, outletName) {
        if (c === oldSegment) {
            children[outletName] = newSegment;
        }
        else {
            children[outletName] = replaceSegment(c, oldSegment, newSegment);
        }
    });
    return new UrlSegmentGroup(current.segments, children);
}
var Navigation = /** @class */ (function () {
    function Navigation(isAbsolute, numberOfDoubleDots, commands) {
        this.isAbsolute = isAbsolute;
        this.numberOfDoubleDots = numberOfDoubleDots;
        this.commands = commands;
        if (isAbsolute && commands.length > 0 && isMatrixParams(commands[0])) {
            throw new Error('Root segment cannot have matrix parameters');
        }
        var cmdWithOutlet = commands.find(function (c) { return typeof c === 'object' && c != null && c.outlets; });
        if (cmdWithOutlet && cmdWithOutlet !== last$1(commands)) {
            throw new Error('{outlets:{}} has to be the last command');
        }
    }
    Navigation.prototype.toRoot = function () {
        return this.isAbsolute && this.commands.length === 1 && this.commands[0] == '/';
    };
    return Navigation;
}());
/** Transforms commands to a normalized `Navigation` */
function computeNavigation(commands) {
    if ((typeof commands[0] === 'string') && commands.length === 1 && commands[0] === '/') {
        return new Navigation(true, 0, commands);
    }
    var numberOfDoubleDots = 0;
    var isAbsolute = false;

View on GitHub (pinned to 8eca2820f3)

Solutions

  1. Move matrix parameters to a segment after the root, not as the first command of an absolute navigation
  2. Use queryParams instead of matrix params if the intent is query-string values
  3. Navigate relatively (without a leading '/'' path-root command) if params must attach to the current segment
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at modules/ui/ui/vendor.js:76718 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of bettercap/bettercap@8eca2820f3 (2026-09-02). Data as JSON: /api/errors/055dd297ac9b992c. Report an issue: GitHub.