in packages/docusaurus/src/server/plugins/routeConfig.ts [30:68]
export function sortConfig(
routeConfigs: RouteConfig[],
baseUrl: string = '/',
): void {
// Sort the route config. This ensures that route with nested
// routes is always placed last.
routeConfigs.sort((a, b) => {
// Root route should get placed last.
if (a.path === baseUrl && b.path !== baseUrl) {
return 1;
}
if (a.path !== baseUrl && b.path === baseUrl) {
return -1;
}
if (a.routes && !b.routes) {
return 1;
}
if (!a.routes && b.routes) {
return -1;
}
// Higher priority get placed first.
if (a.priority || b.priority) {
const priorityA = a.priority || 0;
const priorityB = b.priority || 0;
const score = priorityB - priorityA;
if (score !== 0) {
return score;
}
}
return a.path.localeCompare(b.path);
});
routeConfigs.forEach((routeConfig) => {
routeConfig.routes?.sort((a, b) => a.path.localeCompare(b.path));
});
}