From 53d28de17e9420be51c8c9374a79b49a26343607 Mon Sep 17 00:00:00 2001 From: saopig1 <4x7sw862st@gmail.com> Date: Sat, 30 May 2026 15:11:42 +0800 Subject: [PATCH] feat(scope): router guard syncs + preserves ?bot across navigation --- web/src/router/index.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/web/src/router/index.ts b/web/src/router/index.ts index 3965ceb..25d3b7c 100644 --- a/web/src/router/index.ts +++ b/web/src/router/index.ts @@ -1,5 +1,6 @@ import { createRouter, createWebHistory } from 'vue-router'; import { useSession } from '../composables/useSession.js'; +import { usePlayerStore } from '../stores/player.js'; const router = createRouter({ history: createWebHistory(), @@ -56,6 +57,22 @@ router.beforeEach(async (to) => { if (!session.isAuthenticated.value) { return { name: 'login', query: { next: to.fullPath } }; } + + // Navigation is allowed to proceed to `to` past here (auth/setup redirects above take precedence). + // Sync + preserve the dedicated-link scope carried by ?bot. + const store = usePlayerStore(); + const qBot = typeof to.query.bot === 'string' && to.query.bot ? to.query.bot : null; + if (qBot) { + // URL carries a scope — set tentatively; App.vue's applyScopeFromQuery (after fetchBots) validates/clears it. + store.scopedBotId = qBot; + return true; + } + if (store.scopedBotId) { + // scoped, but this navigation dropped ?bot → re-attach so the lock survives in-app nav + refresh. + if (to.query.bot !== store.scopedBotId) { + return { path: to.path, query: { ...to.query, bot: store.scopedBotId }, hash: to.hash }; + } + } return true; });