shared.js 832 Bytes
export const routeOutlet = () => import("@/layouts/RouteOutlet.vue");

function trimSlashes(path) {
	return (path || "").replace(/^\/+|\/+$/g, "");
}

function joinPaths(parentPath, childPath) {
	const normalizedChild = childPath || "";
	if (normalizedChild.startsWith("/"))
		return normalizedChild;

	const segments = [parentPath, normalizedChild]
		.map(trimSlashes)
		.filter(Boolean);

	return segments.length ? `/${segments.join("/")}` : "/";
}

export function getFirstNavigablePath(routes, parentPath = "") {
	for (const route of routes) {
		const currentPath = joinPaths(parentPath, route.path);

		if (route.children && route.children.length) {
			const childPath = getFirstNavigablePath(route.children, currentPath);
			if (childPath)
				return childPath;
		}

		if (route.name)
			return currentPath;
	}

	return "";
}