Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions packages/router-cli/src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,18 +367,27 @@ function replaceBackslash(s?: string) {
return s?.replace(/\\/gi, '/')
}

function hasParentRoute(routes: RouteNode[], routeToCheck: string | undefined): RouteNode | null {
export function hasParentRoute(routes: RouteNode[], routeToCheck: string | undefined): RouteNode | null {
if (!routeToCheck || routeToCheck === "/") {
return null;
}
for (const route of routes) {

const sortedNodes = multiSortBy(routes, [
(d) => d.routePath!.length * -1,
(d) => d.variableName,

]).filter((d) => d.routePath !== `/${rootPathId}`)

for (const route of sortedNodes) {
if (route.routePath === '/') continue;

if (routeToCheck.startsWith(`${route.routePath}/`) && route.routePath !== routeToCheck) {
return route;
}
}
const segments = routeToCheck.split("/");
segments.pop(); // Remove the last segment
const parentRoute = segments.join("/");

return hasParentRoute(routes, parentRoute);
}