mirror of
https://github.com/FoggedLens/deflock.git
synced 2026-06-30 17:55:42 +02:00
router fix
This commit is contained in:
@@ -422,9 +422,13 @@ const collectionSelectItems = computed<CollectionSelectItem[]>(() => {
|
||||
const collectionId = ref((route.query.category as string) || ALL_COLLECTION_ID);
|
||||
const shopifyContainer = ref<HTMLElement | null>(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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user