cherry-studio/src/renderer/src/handler/NavigationHandler.tsx
MyPrototypeWhat b9a56fcec1 feat(navigation): migrate to TanStack Router and enhance navigation structure
- Replaced react-router with TanStack Router for improved routing capabilities.
- Updated navigation logic across various components to utilize the new navigation API.
- Refactored App.tsx to integrate AppShell as the main routing component, removing the deprecated Router.
- Enhanced navigation methods to support search parameters, improving URL handling for settings and provider navigation.

These changes streamline the routing architecture, enhancing the overall user experience and maintainability of the application.
2025-12-09 17:30:04 +08:00

47 lines
1.2 KiB
TypeScript

import { useAppSelector } from '@renderer/store'
import { IpcChannel } from '@shared/IpcChannel'
import { useLocation, useNavigate } from '@tanstack/react-router'
import { useEffect } from 'react'
import { useHotkeys } from 'react-hotkeys-hook'
const NavigationHandler: React.FC = () => {
const location = useLocation()
const navigate = useNavigate()
const showSettingsShortcutEnabled = useAppSelector(
(state) => state.shortcuts.shortcuts.find((s) => s.key === 'show_settings')?.enabled
)
useHotkeys(
'meta+, ! ctrl+,',
function () {
if (location.pathname.startsWith('/settings')) {
return
}
navigate({ to: '/settings/provider' })
},
{
splitKey: '!',
enableOnContentEditable: true,
enableOnFormTags: true,
enabled: showSettingsShortcutEnabled
}
)
// Listen for navigate to About page event from macOS menu
useEffect(() => {
const handleNavigateToAbout = () => {
navigate({ to: '/settings/about' })
}
const removeListener = window.electron.ipcRenderer.on(IpcChannel.Windows_NavigateToAbout, handleNavigateToAbout)
return () => {
removeListener()
}
}, [navigate])
return null
}
export default NavigationHandler