function handleOriginRoute(route, idx, basePath) { const fullPath = basePath === null ? route.path : basePath + '/' + (route.path || 'index') const filePath = fullPath.replaceAll(/\/\:\w+/g, '') // basePath === null ? route.path : basePath + '/' + (route.path.replaceAll(/\/\:\w+/g, '') || 'index') const children = route?.children?.map((child, idy) => handleOriginRoute(child, idy, fullPath)) const routeName = route.name ?? filePath.replaceAll('/', '-').toUpperCase() return ({ path: route.path, name: routeName, props: /\/\:\w+/.test(basePath + '/' + route.path), meta: Object.assign({ hidden: false, // ['tab', 'single'].includes(route?.plop?.type) || route?.children?.length === 1, breadcrumb: ['tab'].includes(route?.plop?.type), sort: idx, }, route.meta ?? null), plop: { ...route?.plop, filePath, fullPath, props: fullPath.match(/(?<=\/\:)\w+/g), routeName, children: children?.map(child => { const { name, meta: { title } } = child.redirect ? child.children.find(({ name }) => name === child.redirect.name) : child // ?.map(({ name, meta: { title } }) => ({ name, title })) return { name, title } }), template: route?.plop?.type ?? (route?.plop?.url ? 'index' : 'multi') }, component: `___() => import('~/pages${filePath}.vue')___`, children, redirect: Array.isArray(children) ? ({ name: children[0].name }) : null }) } export function origin2target(originRoutes) { const res = originRoutes.map((originRoute, idx) => handleOriginRoute(originRoute, idx, null)) return res //[{ path: '/', redirect: res[0].path, meta: { hidden: true, sort: -1 } }].concat(res) }