mirror of
https://github.com/tuono-labs/tuono
synced 2026-07-30 06:12:47 -07:00
Support nested roots (#18)
* feat: remove isLoader route property * fix: has-parent-route fs-router util * feat: handle routeGenerator nested __root * feat: enable multiple roots with nested dynamic paths * feat: enable nested routes * fix: prevent route path creation for __root * feat: prevent wrong path on subfolder index routes * chore: cleaned tutorial example folder * feat: update version to v0.8.0
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import { ROOT_PATH_ID } from './constants'
|
||||
import { multiSortBy } from './utils'
|
||||
import type { RouteNode } from './types'
|
||||
|
||||
export function hasParentRoute(
|
||||
routes: RouteNode[],
|
||||
node: RouteNode,
|
||||
routePathToCheck = '/',
|
||||
): RouteNode | null {
|
||||
const segments = routePathToCheck.split('/')
|
||||
segments.pop() // Remove the last segment
|
||||
const parentRoutePath = segments.join('/')
|
||||
|
||||
if (!parentRoutePath || parentRoutePath === '/') {
|
||||
return null
|
||||
}
|
||||
|
||||
const sortedNodes = multiSortBy(routes, [
|
||||
(d): number => d.routePath.length * -1,
|
||||
(d): string | undefined => d.variableName,
|
||||
])
|
||||
// Exclude base __root file
|
||||
.filter((d) => d.routePath !== `/${ROOT_PATH_ID}`)
|
||||
|
||||
for (const route of sortedNodes) {
|
||||
if (route.routePath === '/') continue
|
||||
|
||||
if (
|
||||
route.routePath.startsWith(parentRoutePath) &&
|
||||
route.routePath.endsWith(ROOT_PATH_ID)
|
||||
) {
|
||||
return route
|
||||
}
|
||||
}
|
||||
|
||||
return hasParentRoute(routes, node, parentRoutePath)
|
||||
}
|
||||
Reference in New Issue
Block a user