mirror of
https://github.com/ZHANGTIANYAO1/teamspeak-music-bot.git
synced 2026-10-02 04:52:50 +08:00
feat(scope): router guard syncs + preserves ?bot across navigation
This commit is contained in:
1 parent
ca07ebc3b7
commit
53d28de17e
1 file changed
+17
@@ -1,5 +1,6 @@
|
|||||||
import { createRouter, createWebHistory } from 'vue-router';
|
import { createRouter, createWebHistory } from 'vue-router';
|
||||||
import { useSession } from '../composables/useSession.js';
|
import { useSession } from '../composables/useSession.js';
|
||||||
|
import { usePlayerStore } from '../stores/player.js';
|
||||||
|
|
||||||
const router = createRouter({
|
const router = createRouter({
|
||||||
history: createWebHistory(),
|
history: createWebHistory(),
|
||||||
@@ -56,6 +57,22 @@ router.beforeEach(async (to) => {
|
|||||||
if (!session.isAuthenticated.value) {
|
if (!session.isAuthenticated.value) {
|
||||||
return { name: 'login', query: { next: to.fullPath } };
|
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;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user