From 8741b518f81fc1eade7501a27ce320beac326076 Mon Sep 17 00:00:00 2001 From: Will Freeman Date: Wed, 17 Jun 2026 18:56:30 -0600 Subject: [PATCH] router fix --- webapp/src/views/Store.vue | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/webapp/src/views/Store.vue b/webapp/src/views/Store.vue index bf4c4c0..2f0e350 100644 --- a/webapp/src/views/Store.vue +++ b/webapp/src/views/Store.vue @@ -422,9 +422,13 @@ const collectionSelectItems = computed(() => { const collectionId = ref((route.query.category as string) || ALL_COLLECTION_ID); const shopifyContainer = ref(null); -// Sync tab + category to URL so back/forward/refresh restores state +// Sync tab + category to URL so back/forward/refresh restores state. +// Guard prevents re-pushing when the ref update came FROM the router. watch([activeTab, collectionId], ([tab, category]) => { - router.replace({ + const currentTab = (route.query.tab as string) || 'shop'; + const currentCategory = (route.query.category as string) || ALL_COLLECTION_ID; + if (tab === currentTab && category === currentCategory) return; + router.push({ query: { ...(tab !== 'shop' ? { tab } : {}), ...(category !== ALL_COLLECTION_ID ? { category } : {}), @@ -432,6 +436,14 @@ watch([activeTab, collectionId], ([tab, category]) => { }); }, { flush: 'post' }); +// Sync refs back from URL when the user navigates with back/forward. +watch(() => route.query, (query) => { + const newTab = (query.tab as string) || 'shop'; + const newCategory = (query.category as string) || ALL_COLLECTION_ID; + if (activeTab.value !== newTab) activeTab.value = newTab; + if (collectionId.value !== newCategory) collectionId.value = newCategory; +}); + watch(collectionId, (id) => { if (window.ShopifyBuy?.UI) initShopify(id); });