fix: page may redirect to wrong url when switch tabs on Plugins page

This commit is contained in:
NFish 2025-05-16 10:49:21 +08:00
parent 3e37ca05ba
commit 73e4d2df65
1 changed files with 5 additions and 3 deletions

View File

@ -1,4 +1,5 @@
import { usePathname, useSearchParams } from 'next/navigation'
'use client'
import { usePathname, useRouter, useSearchParams } from 'next/navigation'
import { useState } from 'react'
type UseTabSearchParamsOptions = {
@ -25,7 +26,8 @@ export const useTabSearchParams = ({
disableSearchParams = false,
}: UseTabSearchParamsOptions) => {
const pathnameFromHook = usePathname()
const pathName = window?.location?.pathname || pathnameFromHook
const router = useRouter()
const pathName = pathnameFromHook || window?.location?.pathname
const searchParams = useSearchParams()
const [activeTab, setTab] = useState<string>(
!disableSearchParams
@ -37,7 +39,7 @@ export const useTabSearchParams = ({
setTab(newActiveTab)
if (disableSearchParams)
return
history[`${routingBehavior}State`](null, '', `${pathName}?${searchParamName}=${newActiveTab}`)
router[`${routingBehavior}`](`${pathName}?${searchParamName}=${newActiveTab}`)
}
return [activeTab, setActiveTab] as const