async function clearEmptyParams(url: URL) {
let shouldRedirect = false
for (const [key, value] of url.searchParams.entries()) {
if (value === '') {
url.searchParams.delete(key)
shouldRedirect = true
}
}
if (shouldRedirect) {
throw redirect(url.toString())
}
}
export async function loader({ request }: LoaderFunctionArgs) {
const url = new URL(request.url)
await clearEmptyParams(url)
// ... 他のコード
}