Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
sdream-ai-fe
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
侯明涛
sdream-ai-fe
Commits
424cc3c1
Commit
424cc3c1
authored
Dec 09, 2025
by
Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:回滚路由逻辑
parent
94a7e78b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
25 deletions
+6
-25
src/layouts/Navbar/Navbar.tsx
+6
-25
No files found.
src/layouts/Navbar/Navbar.tsx
View file @
424cc3c1
import
type
React
from
'react'
import
type
React
from
'react'
import
{
motion
}
from
'framer-motion'
import
{
motion
}
from
'framer-motion'
import
{
useEffect
,
useRef
,
useState
}
from
'react'
import
{
useEffect
,
useRef
,
useState
}
from
'react'
import
{
use
Location
,
use
Navigate
}
from
'react-router-dom'
import
{
useNavigate
}
from
'react-router-dom'
import
{
useClickAway
,
useSessionStorageState
}
from
'ahooks'
import
{
useClickAway
,
useSessionStorageState
}
from
'ahooks'
import
styles
from
'./Navbar.module.less'
import
styles
from
'./Navbar.module.less'
import
{
NavBarItem
}
from
'./components/NavBarItem'
import
{
NavBarItem
}
from
'./components/NavBarItem'
...
@@ -21,7 +21,6 @@ interface NavbarProps {
...
@@ -21,7 +21,6 @@ interface NavbarProps {
const
NavbarBase
:
React
.
FC
<
NavbarProps
&
WithAuthProps
>
=
({
isHistoryVisible
,
checkAuth
,
onSetHistoryVisible
})
=>
{
const
NavbarBase
:
React
.
FC
<
NavbarProps
&
WithAuthProps
>
=
({
isHistoryVisible
,
checkAuth
,
onSetHistoryVisible
})
=>
{
const
dispatch
=
useAppDispatch
()
const
dispatch
=
useAppDispatch
()
const
navigate
=
useNavigate
()
const
navigate
=
useNavigate
()
const
location
=
useLocation
()
const
{
currentConversationId
,
shouldNavigateToNewConversation
,
currentToolId
}
=
useAppSelector
(
state
=>
state
.
conversation
)
const
{
currentConversationId
,
shouldNavigateToNewConversation
,
currentToolId
}
=
useAppSelector
(
state
=>
state
.
conversation
)
...
@@ -104,29 +103,11 @@ const NavbarBase: React.FC<NavbarProps & WithAuthProps> = ({ isHistoryVisible, c
...
@@ -104,29 +103,11 @@ const NavbarBase: React.FC<NavbarProps & WithAuthProps> = ({ isHistoryVisible, c
useEffect
(()
=>
{
useEffect
(()
=>
{
if
(
shouldNavigateToNewConversation
&&
currentConversationId
)
{
if
(
shouldNavigateToNewConversation
&&
currentConversationId
)
{
// 获取当前 URL 的查询参数,保留除 'from' 之外的所有参数
// 如果当前有选中的 toolId,在 URL 中拼接,以便刷新页面后保留工具选择
const
currentSearchParams
=
new
URLSearchParams
(
location
.
search
)
const
url
=
currentToolId
const
paramsToKeep
=
new
URLSearchParams
()
?
`/chat/
${
currentConversationId
}
?toolId=
${
currentToolId
}
`
// 遍历当前查询参数,过滤掉 'from' 参数
currentSearchParams
.
forEach
((
value
,
key
)
=>
{
if
(
key
!==
'from'
)
{
paramsToKeep
.
set
(
key
,
value
)
}
})
// 如果当前有选中的 toolId,添加到查询参数中
if
(
currentToolId
)
{
paramsToKeep
.
set
(
'toolId'
,
currentToolId
)
}
// 构建跳转 URL
const
queryString
=
paramsToKeep
.
toString
()
const
url
=
queryString
?
`/chat/
${
currentConversationId
}
?
${
queryString
}
`
:
`/chat/
${
currentConversationId
}
`
:
`/chat/
${
currentConversationId
}
`
// 通过 location.state 传递 toolId,避免在 Chat 页面被误判为“外链残留参数”而强制清空
// 通过 location.state 传递 toolId,避免在 Chat 页面被误判为"外链残留参数"而强制清空
navigate
(
url
,
{
navigate
(
url
,
{
state
:
{
state
:
{
toolId
:
currentToolId
||
null
,
toolId
:
currentToolId
||
null
,
...
@@ -134,7 +115,7 @@ const NavbarBase: React.FC<NavbarProps & WithAuthProps> = ({ isHistoryVisible, c
...
@@ -134,7 +115,7 @@ const NavbarBase: React.FC<NavbarProps & WithAuthProps> = ({ isHistoryVisible, c
})
})
dispatch
(
clearNavigationFlag
())
dispatch
(
clearNavigationFlag
())
}
}
},
[
shouldNavigateToNewConversation
,
currentConversationId
,
currentToolId
,
navigate
,
dispatch
,
location
.
search
])
},
[
shouldNavigateToNewConversation
,
currentConversationId
,
currentToolId
,
navigate
,
dispatch
])
// keep latest conversation id in sessionStorage for cross-page returns (e.g., from collect)
// keep latest conversation id in sessionStorage for cross-page returns (e.g., from collect)
useEffect
(()
=>
{
useEffect
(()
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment