Skip to content

useTransitionRouter It doesn't work if the URL has parameters #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
FSSRepo opened this issue Apr 25, 2025 · 0 comments
Open

useTransitionRouter It doesn't work if the URL has parameters #30

FSSRepo opened this issue Apr 25, 2025 · 0 comments

Comments

@FSSRepo
Copy link

FSSRepo commented Apr 25, 2025

  const router = useTransitionRouter();

  const [selectedBrand, setSelectedBrand] = useState('');
  const [selectedType, setSelectedType] = useState('');
  const [selectedGender, setSelectedGender] = useState('');

  useEffect(() => {
    setSelectedBrand(searchParams.get('brand') ?? '');
    setSelectedType(searchParams.get('type') ?? '');
    setSelectedGender(searchParams.get('gender') ?? '');
  }, [searchParams]);

  const updateParam = (param: string, value: string) => {
    const params = new URLSearchParams(Array.from(searchParams.entries()));
    if (value) params.set(param, value);
    else params.delete(param);
    if(param == 'brand') {
      params.delete('search');
    }
    router.push( `${pathname != '/products' ? '/products' : pathname}?${params.toString()}`); // this doesn't work
  };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant