UNPKG

phx-react

Version:

PHX REACT

32 lines 1.3 kB
import { PHXUseDirectLink } from '../../../hooks/direct-link'; export default function PHXUrlApply(key, value, listKeyResetParams, configUrlApply, onlyResetValueUrl) { const isUseUrlApply = configUrlApply && key && value !== undefined; const listKeyReset = listKeyResetParams !== null && listKeyResetParams !== void 0 ? listKeyResetParams : []; if (isUseUrlApply) { const { router, searchParams, replaceUrl } = configUrlApply; // Clone current params const params = new URLSearchParams(searchParams.toString()); const defaultValue = '0'; if (!onlyResetValueUrl) { params.set(key, value); } for (const keyReset of listKeyReset) { params.set(keyReset, defaultValue); } const paramValue = params.toString().toLowerCase(); if (router) { // Push to URL without reload if (replaceUrl) { router.replace(`?${paramValue}`, { scroll: false }); } else { router.push(`?${paramValue}`, { scroll: false }); } } else { const directLink = PHXUseDirectLink(); directLink(`?${paramValue}`, { replace: replaceUrl }); } } } //# sourceMappingURL=PHXUrlApply.js.map