1- import { createLazyFileRoute } from '@tanstack/react-router' ;
1+ import { createLazyFileRoute , useNavigate , useSearch as useSearchParams , Link } from '@tanstack/react-router' ;
22import { useState , useEffect } from 'react' ;
33import { useSearch } from '../hooks/useSearch' ;
44import { useProfile } from '../hooks/useProfile' ;
5- import { Link } from '@tanstack/react-router' ;
65import { LuSearch , LuMapPin , LuMail , LuGlobe , LuTwitter , LuGithub , LuMessageSquare , LuSend } from "react-icons/lu" ;
76import { useDebounce } from 'use-debounce' ;
87import { getChainIconUrl } from '../utils/chainIcons' ;
98import { shouldAttemptDirectLookup } from '../utils/validation' ;
109import { ChainIcon } from '../components/ChainIcon' ;
1110
11+ interface SearchParams {
12+ q ?: string
13+ }
14+
1215export const Route = createLazyFileRoute ( '/' ) ( {
1316 component : Home ,
1417} ) ;
@@ -111,7 +114,9 @@ function ProfileFallback({ searchTerm }: { searchTerm: string }) {
111114}
112115
113116function Home ( ) {
114- const [ searchInput , setSearchInput ] = useState ( '' ) ;
117+ const navigate = useNavigate ( ) ;
118+ const params = new URLSearchParams ( typeof window !== 'undefined' ? window . location . search : '' ) ;
119+ const [ searchInput , setSearchInput ] = useState ( params . get ( 'q' ) || '' ) ;
115120 const [ debouncedSearchTerm ] = useDebounce ( searchInput , 300 ) ;
116121 const { data, isLoading, error } = useSearch ( debouncedSearchTerm ) ;
117122
@@ -127,8 +132,29 @@ function Home() {
127132 }
128133 } , [ isLoading , data ] ) ;
129134
135+ // Update URL when search term changes
136+ useEffect ( ( ) => {
137+ if ( typeof window === 'undefined' ) return ;
138+
139+ const currentParams = new URLSearchParams ( window . location . search ) ;
140+ if ( debouncedSearchTerm ) {
141+ currentParams . set ( 'q' , debouncedSearchTerm ) ;
142+ } else {
143+ currentParams . delete ( 'q' ) ;
144+ }
145+
146+ const newSearch = currentParams . toString ( ) ;
147+ const newPath = window . location . pathname + ( newSearch ? `?${ newSearch } ` : '' ) ;
148+
149+ navigate ( {
150+ to : newPath ,
151+ replace : true ,
152+ } ) ;
153+ } , [ debouncedSearchTerm , navigate ] ) ;
154+
130155 const handleSearch = ( e : React . FormEvent ) => {
131156 e . preventDefault ( ) ;
157+ // The URL will be updated by the effect above
132158 } ;
133159
134160 // Render search results or appropriate message
0 commit comments