fix: menu and routing

This commit is contained in:
2026-03-30 16:39:14 +02:00
parent 68f4850445
commit 91c5de1f67
18 changed files with 728 additions and 228 deletions

View File

@@ -49,6 +49,42 @@ const router = createRouter({
],
})
const viewModules = import.meta.glob('/src/views/**/*.vue')
const componentModules = import.meta.glob('/src/components/**/*.vue')
async function setRoutes() {
const routes = await getRoutes()
for (const item of routes) {
const componentName = item.component
const [, folder] = componentName.split('/')
const componentPath = `/src${componentName}`
console.log(componentPath);
let modules =
folder === 'views' ? viewModules : componentModules
const importer = modules[componentPath]
if (!importer) {
console.error('Component not found:', componentPath)
continue
}
const importedComponent = (await importer()).default
router.addRoute('locale', {
path: item.path,
component: importedComponent,
name: item.name,
meta: item.meta ? JSON.parse(item.meta) : {}
})
}
}
await setRoutes()
router.beforeEach((to, from) => {
const locale = to.params.locale as string
const localeLang = langs.find((x) => x.iso_code === locale)