fix: safe router.back() — fallback to home if no history (prevents navigating to external site)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
saopig1andClaude Opus 4.6 committed 2026-03-30 14:57:32 +08:00
1 parent eb0088d110
commit 7d329a0db1
2 files changed
+17 -2

No files matched your search

+6 -1
View File
@@ -89,7 +89,12 @@ const currentSong = computed(() => store.currentSong);
function toggleLyrics() { function toggleLyrics() {
if (route.path === '/lyrics') { if (route.path === '/lyrics') {
router.back(); // Go back if there's history, otherwise go home
if (window.history.length > 1) {
router.back();
} else {
router.push('/');
}
} else { } else {
router.push('/lyrics'); router.push('/lyrics');
} }
+11 -1
View File
@@ -1,7 +1,7 @@
<template> <template>
<div class="lyrics-page" :style="bgStyle"> <div class="lyrics-page" :style="bgStyle">
<div class="lyrics-overlay" /> <div class="lyrics-overlay" />
<button class="back-btn" @click="$router.back()"> <button class="back-btn" @click="goBack">
<Icon icon="mdi:arrow-left" /> <Icon icon="mdi:arrow-left" />
返回 返回
</button> </button>
@@ -46,14 +46,24 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, computed, watch, onMounted, onUnmounted } from 'vue'; import { ref, computed, watch, onMounted, onUnmounted } from 'vue';
import { useRouter } from 'vue-router';
import { Icon } from '@iconify/vue'; import { Icon } from '@iconify/vue';
import axios from 'axios'; import axios from 'axios';
import { usePlayerStore } from '../stores/player.js'; import { usePlayerStore } from '../stores/player.js';
import CoverArt from '../components/CoverArt.vue'; import CoverArt from '../components/CoverArt.vue';
const router = useRouter();
const store = usePlayerStore(); const store = usePlayerStore();
const currentSong = computed(() => store.currentSong); const currentSong = computed(() => store.currentSong);
function goBack() {
if (window.history.length > 1) {
router.back();
} else {
router.push('/');
}
}
interface LyricLine { interface LyricLine {
time: number; time: number;
text: string; text: string;