fix: sidebar highlight on detail pages with numeric IDs

When visiting /merchants/billing/subscriptions/3, currentPage was set
to '3' instead of 'subscriptions'. Now skips numeric trailing segments
so the parent page stays highlighted. Applied to both merchant and
store init-alpine.js.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-22 23:08:17 +01:00
parent 467b1510f4
commit 716a4e3d15
2 changed files with 10 additions and 2 deletions

View File

@@ -54,7 +54,11 @@ function data() {
const segments = path.split('/').filter(Boolean);
// For /merchants/dashboard -> 'dashboard'
// For /merchants/billing/subscriptions -> 'subscriptions'
this.currentPage = segments[segments.length - 1] || 'dashboard';
// For /merchants/billing/subscriptions/3 -> 'subscriptions' (skip numeric IDs)
const last = segments[segments.length - 1] || 'dashboard';
this.currentPage = /^\d+$/.test(last) && segments.length > 2
? segments[segments.length - 2]
: last;
// Load merchant name from JWT token
const token = localStorage.getItem('merchant_token');

View File

@@ -58,7 +58,11 @@ function data() {
// Set current page from URL
const path = window.location.pathname;
const segments = path.split('/').filter(Boolean);
this.currentPage = segments[segments.length - 1] || 'dashboard';
// 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 URL
if (segments[0] === 'store' && segments[1]) {