scripts/routes/route-map.js
function _addRouteRecord(route, parent, exclude = false, ancestors = []) {
    const { path, name, handler } = route;
    const finalPath = _normalizePath(path, parent, ancestors);

    // Push path into ancestors array
    ancestors.push(path);

    const record = {
        name,
        parent,
        handler,
        path: finalPath,
        regex: PathToRegexp(finalPath),
        // redirect, TODO: Look into redirect functionality further
        before: route.before,
        init: route.init,
        update: route.update,
        after: route.after,
        unload: route.unload,
        pop: route.pop,
        meta: route.meta || {},
    };

    // Children should be mapped before parent in case of wildcard in parent
    if (route.children && route.children.length) {
        let i = 0;
        const length = route.children.length;

        for (; i < length; i++) {
            _addRouteRecord(route.children[i], route, exclude, ancestors);

            // After record is added, pop last ancestor off for the next set of paths
            ancestors.pop();
        }
    }

    // Exclude from main mapping/return created route record object
    if (exclude) {
        return record;
    }

    if (! pathMap[record.path]) {
        pathList.push(record.path);
        pathMap[record.path] = record;
    }

    if (name && ! nameMap[name]) {
        nameMap[name] = record;
    }
}
function _addRouteRecord(route, parent, exclude = false, ancestors = []) {
    const { path, name, handler } = route;
    const finalPath = _normalizePath(path, parent, ancestors);

    // Push path into ancestors array
    ancestors.push(path);

    const record = {
        name,
        parent,
        handler,
        path: finalPath,
        regex: PathToRegexp(finalPath),
        // redirect, TODO: Look into redirect functionality further
        before: route.before,
        init: route.init,
        update: route.update,
        after: route.after,
        unload: route.unload,
        pop: route.pop,
        meta: route.meta || {},
    };

    // Children should be mapped before parent in case of wildcard in parent
    if (route.children && route.children.length) {
        let i = 0;
        const length = route.children.length;

        for (; i < length; i++) {
            _addRouteRecord(route.children[i], route, exclude, ancestors);

            // After record is added, pop last ancestor off for the next set of paths
            ancestors.pop();
        }
    }

    // Exclude from main mapping/return created route record object
    if (exclude) {
        return record;
    }

    if (! pathMap[record.path]) {
        pathList.push(record.path);
        pathMap[record.path] = record;
    }

    if (name && ! nameMap[name]) {
        nameMap[name] = record;
    }
}
function _addRouteRecord ( route , parent , exclude = false , ancestors = [ ] ) { const { path , name , handler } = route ; const finalPath = _normalizePath ( path , parent , ancestors ) ; // Push path into ancestors array ancestors . push ( path ) ; const record = { name , parent , handler , path : finalPath , regex : PathToRegexp ( finalPath ) , // redirect, TODO: Look into redirect functionality further before : route . before , init : route . init , update : route . update , after : route . after , unload : route . unload , pop : route . pop , meta : route . meta || { } , } ; // Children should be mapped before parent in case of wildcard in parent if ( route . children && route . children . length ) { let i = 0 ; const length = route . children . length ; for ( ; i < length ; i ++ ) { _addRouteRecord ( route . children [ i ] , route , exclude , ancestors ) ; // After record is added, pop last ancestor off for the next set of paths ancestors . pop ( ) ; } } // Exclude from main mapping/return created route record object if ( exclude ) { return record ; } if ( ! pathMap [ record . path ] ) { pathList . push ( record . path ) ; pathMap [ record . path ] = record ; } if ( name && ! nameMap [ name ] ) { nameMap [ name ] = record ; } }
Register new route

@param {Object} route
@param {Object} [parent]
@param {boolean} exclude
@private
Register new route