mirror of
https://github.com/langgenius/dify.git
synced 2026-04-28 03:36:36 +08:00
fix: page may redirect to wrong url when switch tabs on Plugins page
This commit is contained in:
parent
3e37ca05ba
commit
73e4d2df65
@ -1,4 +1,5 @@
|
|||||||
import { usePathname, useSearchParams } from 'next/navigation'
|
'use client'
|
||||||
|
import { usePathname, useRouter, useSearchParams } from 'next/navigation'
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
|
|
||||||
type UseTabSearchParamsOptions = {
|
type UseTabSearchParamsOptions = {
|
||||||
@ -25,7 +26,8 @@ export const useTabSearchParams = ({
|
|||||||
disableSearchParams = false,
|
disableSearchParams = false,
|
||||||
}: UseTabSearchParamsOptions) => {
|
}: UseTabSearchParamsOptions) => {
|
||||||
const pathnameFromHook = usePathname()
|
const pathnameFromHook = usePathname()
|
||||||
const pathName = window?.location?.pathname || pathnameFromHook
|
const router = useRouter()
|
||||||
|
const pathName = pathnameFromHook || window?.location?.pathname
|
||||||
const searchParams = useSearchParams()
|
const searchParams = useSearchParams()
|
||||||
const [activeTab, setTab] = useState<string>(
|
const [activeTab, setTab] = useState<string>(
|
||||||
!disableSearchParams
|
!disableSearchParams
|
||||||
@ -37,7 +39,7 @@ export const useTabSearchParams = ({
|
|||||||
setTab(newActiveTab)
|
setTab(newActiveTab)
|
||||||
if (disableSearchParams)
|
if (disableSearchParams)
|
||||||
return
|
return
|
||||||
history[`${routingBehavior}State`](null, '', `${pathName}?${searchParamName}=${newActiveTab}`)
|
router[`${routingBehavior}`](`${pathName}?${searchParamName}=${newActiveTab}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
return [activeTab, setActiveTab] as const
|
return [activeTab, setActiveTab] as const
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user