Search page redirects
Last updated
Was this helpful?
Was this helpful?
// src/components/Search/Search.tsx
export default function Search() {
const { newSearch } = useActions();
const onSubmit = (query: string) => {
// If we are already on the search page, just update the results
if (window.location.pathname.includes("/search")) {
newSearch({ query });
} else {
// Otherwise, redirect to the main search page
window.location.href = `/search?q=${encodeURIComponent(query)}`;
}
};
// ... component JSX that uses onSubmit
}