fix(core): don't overwrite currentPage set by child Alpine components

The store init-alpine.js init() was unconditionally setting currentPage
from the URL path segment, overwriting the value set by child components
like storeLoyaltyProgram (currentPage: 'loyalty-program'). This caused
sidebar menu items to not highlight on pages where the URL segment
doesn't match the menu item ID (e.g., /loyalty/program vs loyalty-program).

Now only sets currentPage from URL if the child hasn't already set it.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-23 18:22:20 +01:00
parent 33f823aba0
commit ce0caa5685

View File

@@ -65,14 +65,16 @@ function data() {
openSections: getStoreSidebarSectionsFromStorage(),
init() {
// Set current page from URL
const path = window.location.pathname;
const segments = path.split('/').filter(Boolean);
// For /store/ABC/orders/123 -> 'orders' (skip numeric IDs)
const last = segments[segments.length - 1] || 'dashboard';
this.currentPage = /^\d+$/.test(last) && segments.length > 2
? segments[segments.length - 2]
: last;
// Set current page from URL (only if not already set by child component)
if (!this.currentPage) {
const path = window.location.pathname;
const segments = path.split('/').filter(Boolean);
// For /store/ABC/orders/123 -> 'orders' (skip numeric IDs)
const last = segments[segments.length - 1] || 'dashboard';
this.currentPage = /^\d+$/.test(last) && segments.length > 2
? segments[segments.length - 2]
: last;
}
// Get store code from server-rendered value or URL fallback
this.storeCode = window.STORE_CODE || null;