Skip to content
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

Make querystring available in load() #2290

Closed
icalvin102 opened this issue Aug 25, 2021 · 1 comment
Closed

Make querystring available in load() #2290

icalvin102 opened this issue Aug 25, 2021 · 1 comment
Labels
feature request New feature or request p2-nice-to-have SvelteKit cannot be used by a small number of people, quality of life improvements, etc.

Comments

@icalvin102
Copy link
Contributor

icalvin102 commented Aug 25, 2021

Describe the problem

The page.query in the load function is a instance of URLSearchParams which is fine for cases that use standard queries.
However there are many commonly used ways to use the query of a URL that do not work well with URLSearchParams.

Using comma separated values for example is a commonly used practice that can fail with URLSearchParams.

Consider the following example:

const categories = [
'articles',
'cats,dogs'
];

const querystring = `categories=${categories.map(encodeURIComponent).join(',')}`;

console.log(querystring);
console.log((new URLSearchParams(querystring)).toString());

// Console output
// categories=articles,cats%2Cdogs
// categories=articles%2Ccats%2Cdogs

The output is clearly not the same and it is impossible to get the correct value from the instance of URLSearchParams.
The input should be interpreted as a array of length 2 with the contents articles, cats,dogs but it gets interpreted as a array of length 3 with the values articles, cats, dogs.

Describe the proposed solution

Pass a page.querystring property with the unparsed querystring alongside with page.query to the load function.

Alternatives considered

On the client the location.search can be used instead of page.query but this is not available on the server.

Importance

would make my life easier

Additional Information

No response

@benmccann benmccann changed the title Make querystring availible in load() Make querystring available in load() Aug 25, 2021
@benmccann benmccann added feature request New feature or request p2-nice-to-have SvelteKit cannot be used by a small number of people, quality of life improvements, etc. labels Aug 25, 2021
@icalvin102
Copy link
Contributor Author

icalvin102 commented Feb 6, 2022

Implemented by #3133 which makes the whole URL object available in load.
The querystring can now be accessed trough url.search

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request p2-nice-to-have SvelteKit cannot be used by a small number of people, quality of life improvements, etc.
Projects
None yet
Development

No branches or pull requests

2 participants