Upgrade Express to version 5.2.1 and update related dependencies in package.json and package-lock.json. Refactor server CORS configuration to accommodate Express 5 changes. Enhance routing logic in Vue components for improved path normalization and menu handling. Update HTML asset references for better loading performance and accessibility improvements in various components.
This commit is contained in:
@@ -33,17 +33,32 @@ function loadComponent(componentName) {
|
||||
};
|
||||
}
|
||||
|
||||
function normalizePath(path) {
|
||||
if (!path || typeof path !== 'string') {
|
||||
return '/';
|
||||
}
|
||||
let value = path.trim();
|
||||
if (!value.startsWith('/')) {
|
||||
value = `/${value}`;
|
||||
}
|
||||
if (value.length > 1) {
|
||||
value = value.replace(/\/+$/, '');
|
||||
}
|
||||
return value || '/';
|
||||
}
|
||||
|
||||
function generateRoutesFromMenu(menu) {
|
||||
let routes = [];
|
||||
menu.forEach(item => {
|
||||
if (item.link === '/admin/edit-pages') {
|
||||
const normalizedLink = normalizePath(item.link || '');
|
||||
if (normalizedLink === '/admin/edit-pages') {
|
||||
return;
|
||||
}
|
||||
|
||||
let route = null;
|
||||
if (item.link && item.link !== '') {
|
||||
route = {
|
||||
path: item.link,
|
||||
path: normalizedLink,
|
||||
meta: { requiresAuth: item.requiresAuth || false },
|
||||
components: {
|
||||
default: loadComponent(item.component),
|
||||
@@ -63,6 +78,43 @@ function generateRoutesFromMenu(menu) {
|
||||
return routes;
|
||||
}
|
||||
|
||||
function findMenuItemByPath(menu, targetPath) {
|
||||
const wanted = normalizePath(targetPath);
|
||||
for (const item of menu || []) {
|
||||
if (normalizePath(item.link || '') === wanted) {
|
||||
return item;
|
||||
}
|
||||
if (item.submenu && item.submenu.length > 0) {
|
||||
const found = findMenuItemByPath(item.submenu, wanted);
|
||||
if (found) {
|
||||
return found;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function ensureMenuRouteForPath(path) {
|
||||
const normalizedPath = normalizePath(path);
|
||||
const exists = router.getRoutes().some(r => normalizePath(r.path) === normalizedPath);
|
||||
if (exists) {
|
||||
return true;
|
||||
}
|
||||
const menuItem = findMenuItemByPath(store.state.menuData, normalizedPath);
|
||||
if (!menuItem || !menuItem.link) {
|
||||
return false;
|
||||
}
|
||||
router.addRoute({
|
||||
path: normalizedPath,
|
||||
meta: { requiresAuth: menuItem.requiresAuth || false },
|
||||
components: {
|
||||
default: loadComponent(menuItem.component),
|
||||
rightColumn: loadComponent('ImageContent')
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
routes: []
|
||||
@@ -96,10 +148,24 @@ router.beforeEach(async (to, from, next) => {
|
||||
});
|
||||
}
|
||||
|
||||
const normalizedToPath = normalizePath(to.path);
|
||||
if (normalizedToPath !== to.path) {
|
||||
next({ path: normalizedToPath, query: to.query, hash: to.hash, replace: true });
|
||||
return;
|
||||
}
|
||||
next({ ...to, replace: true });
|
||||
} else {
|
||||
// Sicherstellen, dass Kernrouten immer verfügbar sind
|
||||
ensureCoreRoutes();
|
||||
const normalizedToPath = normalizePath(to.path);
|
||||
if (normalizedToPath !== to.path) {
|
||||
next({ path: normalizedToPath, query: to.query, hash: to.hash, replace: true });
|
||||
return;
|
||||
}
|
||||
if (to.matched.length === 0 && ensureMenuRouteForPath(normalizedToPath)) {
|
||||
next({ path: normalizedToPath, query: to.query, hash: to.hash, replace: true });
|
||||
return;
|
||||
}
|
||||
if (to.matched.some(record => record.meta.requiresAuth) && !store.getters.isLoggedIn) {
|
||||
next('/auth/login');
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user