Modificaciones

This commit is contained in:
Ignacio Martinez Navajas
2025-05-05 16:30:11 +02:00
parent 95e10820a3
commit 1ebc22c74b
2 changed files with 38 additions and 4 deletions

View File

@ -0,0 +1,32 @@
<?php
if (!function_exists('active_route')) {
/**
* Devuelve 'active' si la ruta actual coincide con la proporcionada.
*
* @param string $routeName Nombre de la ruta definida en route_to().
* @return string
*/
function active_route(string $routeName): string
{
try {
return current_url() === route_to($routeName) ? 'active' : '';
} catch (\Exception $e) {
return ''; // Por si la ruta no existe o lanza error
}
}
}
if (!function_exists('active_uri_starts_with')) {
/**
* Devuelve 'open active' si uri_string() comienza con el prefijo dado.
* Útil para marcar menús padres.
*
* @param string $prefix Prefijo del URI, como 'config', 'catalogo', etc.
* @return string
*/
function active_uri_starts_with(string $prefix): string
{
return str_starts_with(uri_string(), $prefix) ? 'open active' : '';
}
}

View File

@ -424,12 +424,14 @@ $picture = "/assets/img/default-user.png";
tempAnchor.href = href;
const linkPath = tempAnchor.pathname;
// Comparación exacta de ruta
if (browserUrl === linkPath) {
// Corrección: coincide si es igual o si browserUrl empieza con el linkPath + '/'
if (browserUrl === linkPath || browserUrl.startsWith(linkPath + '/')) {
const menuItem = link.closest('.menu-item');
menuItem.classList.add('active');
if (menuItem) {
menuItem.classList.add('active');
}
const parent = menuItem.closest('.menu-sub');
const parent = menuItem?.closest('.menu-sub');
if (parent) {
const parentItem = parent.closest('.menu-item');
if (parentItem) {