public map()

in packages/web-components/fast-router/src/routes.ts [281:340]


    public map(...routes: MappableRouteDefinition<TSettings>[]) {
        for (const route of routes) {
            if ("children" in route) {
                const titleBuilder = this.owner.createTitleBuilder();
                const childRoutes = route.children.map(x => {
                    const childRoute = {
                        ...route,
                        ...x,
                        path: `${route.path}/${x.path}`,
                    };

                    if ("title" in route || "title" in x) {
                        const parentTitle = (route as HasTitle).title || "";
                        const childTitle = (x as HasTitle).title || "";
                        (childRoute as HasTitle).title = titleBuilder.joinTitles(
                            parentTitle,
                            childTitle
                        );
                    }

                    if ("name" in x) {
                        const parentName = route.name ? route.name + "/" : "";
                        childRoute.name = parentName + x.name;
                    }

                    if (childRoute.children === route.children) {
                        delete (childRoute as any).children;
                    }

                    return childRoute;
                });

                this.map(...childRoutes);
                continue;
            }

            let command: NavigationCommand;

            if ("command" in route) {
                command = route.command;
            } else if ("redirect" in route) {
                command = new Redirect(route.redirect);
            } else {
                command = Render.fromDefinition(this.owner, route);
            }

            this.pathToCommand.set(route.path, command);
            this.recognizer.add(route, route.settings);

            if ("childRouters" in route && route.childRouters) {
                const childRouterRoute = {
                    ...route,
                    path: route.path + `/*${childRouteParameter}`,
                };

                this.pathToCommand.set(childRouterRoute.path, command);
                this.recognizer.add(childRouterRoute, childRouterRoute.settings);
            }
        }
    }