Skip to content

SearchParameters no longer encoded as JSON #711

@sowhatdoido

Description

@sowhatdoido

Describe the bug

Discussed on Discord

According to https://tanstack.com/router/v1/docs/guide/search-params#json-first-search-params, JSON is supported in search parameters and is encoded into something like: /shop?pageIndex=3&includeCategories=%5B%22electronics%22%2C%22gifts%22%5D&sortBy=price&desc=true

However in a sandbox I'm using to test this functionality, I'm noticing that arrays are represented as key=firstValue&key=secondValue. Calling useSearch() against this results in { key: ['firstValue', 'secondValue'] }.

The issue is that if you set an array of 1, the url is in the same format as if you didn't use an array at all, thus calling useSearch results in { key: 'firstValue' } instead of { key: ['firstValue']}.

This occurs using both: router.navigate({ key: ['firstValue'] }) and <Link search={{ key: ['firstValue'] }} />

Your Example Website or App

https://codesandbox.io/s/tanstack-array-in-search-params-issue-c3nzt3?file=/src/App.js

Steps to Reproduce the Bug or Issue

Described above.

Expected behavior

SearchParams should be able to distinguish between arrays with single values and actual single values properly, whether that's through JSON encoded as described in the documentation or some customizable, opinionated format.

Screenshots or Videos

No response

Platform

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions