This repository has been archived on 2024-12-07. You can view files and clone it, but cannot push or open issues or pull requests.
Cinemateket/frontend/src/util/navigate.ts
2023-09-15 08:35:31 +02:00

19 lines
448 B
TypeScript

import { useNavigate } from 'react-router'
export const useNavigateToPage = () => {
const navigate = useNavigate()
return (title?: string, type?: string, year?: string, page: string = '1') => {
if (!title) {
navigate('')
window.location.reload()
} else {
let query = `?title=${title}&page=${page}`
if (type) query += `&type=${type}`
if (year) query += `&year=${year}`
navigate(query)
}
}
}