Based on react-router@v6
function generatePaths(route: RouteObject, parentPath = '') {
const { path, children } = route
const fullPath = cleanDoubleSlashes(withoutTrailingSlash(`${parentPath}/${path ?? ''}`))
let paths = new Set([fullPath])
if (children) {
for (const childRoute of children) {
const childPaths = generatePaths(childRoute, fullPath)
paths = new Set([...paths, ...childPaths])
}
}
return paths
}
// Paths should be uniq
const paths = routes.flatMap(route => Array.from(generatePaths(route)))