@@ -4,53 +4,51 @@ import { getAvailablePlatforms, getPlatformById, type PlatformInfo } from "@/dat
44import { formatReleaseDate , formatVersion , getLatestRelease , type GitHubRelease } from "@/lib/github" ;
55import { useI18n } from "@/lib/i18n" ;
66import { BookOpenIcon , MessageCircleIcon } from "lucide-react" ;
7- import { useRouter , useSearchParams } from "next/navigation" ;
8- import { Suspense , useEffect , useState } from "react" ;
7+ import { useEffect , useState } from "react" ;
98import DownloadSection from "./components/download-section" ;
109import PlatformSelector from "./components/platform-selector" ;
1110
12- function DownloadPageContent ( ) {
11+ export default function DownloadPage ( ) {
1312 const { tw, locale } = useI18n ( ) ;
14- const router = useRouter ( ) ;
15- const searchParams = useSearchParams ( ) ;
1613 const availablePlatforms = getAvailablePlatforms ( ) ;
1714
18- // 从 URL 中获取平台参数,如果没有则使用第一个可用平台
15+ // 状态管理
1916 const [ selectedPlatform , setSelectedPlatform ] = useState < PlatformInfo | null > ( null ) ;
20-
21- // GitHub 版本信息状态
2217 const [ release , setRelease ] = useState < GitHubRelease | null > ( null ) ;
2318 const [ isLoadingRelease , setIsLoadingRelease ] = useState ( true ) ;
2419
2520 // 初始化选中的平台
2621 useEffect ( ( ) => {
27- const platformParam = searchParams . get ( 'platform' ) ;
28- if ( platformParam ) {
29- const platform = getPlatformById ( platformParam ) ;
30- if ( platform && platform . available ) {
31- setSelectedPlatform ( platform ) ;
32- } else {
33- // 如果 URL 中的平台无效,使用第一个可用平台并更新 URL
34- const defaultPlatform = availablePlatforms . length > 0 ? availablePlatforms [ 0 ] : null ;
35- setSelectedPlatform ( defaultPlatform ) ;
36- if ( defaultPlatform ) {
37- router . replace ( `/download?platform=${ defaultPlatform . id } ` ) ;
22+ // 从 URL 获取平台参数(仅在客户端)
23+ if ( typeof window !== 'undefined' ) {
24+ const urlParams = new URLSearchParams ( window . location . search ) ;
25+ const platformParam = urlParams . get ( 'platform' ) ;
26+
27+ if ( platformParam ) {
28+ const platform = getPlatformById ( platformParam ) ;
29+ if ( platform && platform . available ) {
30+ setSelectedPlatform ( platform ) ;
31+ return ;
3832 }
3933 }
40- } else {
41- // 如果没有平台参数,使用第一个可用平台并更新 URL
42- const defaultPlatform = availablePlatforms . length > 0 ? availablePlatforms [ 0 ] : null ;
43- setSelectedPlatform ( defaultPlatform ) ;
44- if ( defaultPlatform ) {
45- router . replace ( `/download?platform=${ defaultPlatform . id } ` ) ;
46- }
4734 }
48- } , [ searchParams , router , availablePlatforms ] ) ;
35+
36+ // 如果没有有效的平台参数,使用第一个可用平台
37+ if ( availablePlatforms . length > 0 ) {
38+ setSelectedPlatform ( availablePlatforms [ 0 ] ) ;
39+ }
40+ } , [ availablePlatforms ] ) ;
4941
5042 // 处理平台选择变化
5143 const handlePlatformChange = ( platform : PlatformInfo ) => {
5244 setSelectedPlatform ( platform ) ;
53- router . push ( `/download?platform=${ platform . id } ` ) ;
45+
46+ // 更新 URL(仅在客户端)
47+ if ( typeof window !== 'undefined' ) {
48+ const newUrl = new URL ( window . location . href ) ;
49+ newUrl . searchParams . set ( 'platform' , platform . id ) ;
50+ window . history . replaceState ( { } , '' , newUrl . toString ( ) ) ;
51+ }
5452 } ;
5553
5654 // 获取最新版本信息
@@ -191,18 +189,3 @@ function DownloadPageContent() {
191189 </ main >
192190 ) ;
193191}
194-
195- export default function DownloadPage ( ) {
196- return (
197- < Suspense fallback = {
198- < div className = "min-h-screen flex items-center justify-center" >
199- < div className = "text-center" >
200- < div className = "animate-spin rounded-full h-8 w-8 border-b-2 border-primary mx-auto mb-4" > </ div >
201- < p className = "text-muted-foreground" > 加载中...</ p >
202- </ div >
203- </ div >
204- } >
205- < DownloadPageContent />
206- </ Suspense >
207- ) ;
208- }
0 commit comments