Skip to content

Commit

Permalink
Merge pull request #199 from PierBover/URLSearchParams-docs
Browse files Browse the repository at this point in the history
Added information about using URLSearchParams
  • Loading branch information
ItalyPaleAle authored Mar 2, 2021
2 parents ab03300 + ebc0e02 commit 0bceac3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions Advanced Usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,9 @@ The current page is: /search
The querystring is: query=hello+world&sort=title
````

Most times, however, you might want to parse the "querystring" into a dictionary, to be able to use those values inside your application easily. There are multiple ways of doing that (some as simple as [a few lines of JavaScript](https://stackoverflow.com/questions/2090551/parse-query-string-in-javascript)), but a good, robust and safe solution is to rely on the popular library [qs](https://www.npmjs.com/package/qs).
Most times, however, you might want to parse the "querystring" into a dictionary, to be able to use those values inside your application easily. There are multiple ways of doing that. The simplest one is using [URLSearchParams](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams) which is available in all modern browsers. If you need support for older browsers, a safe solution is to rely on the popular [qs](https://www.npmjs.com/package/qs) library.

For example, changing the component above to:
Here's an example on using `qs` by changing the component above to:

````svelte
<script>
Expand All @@ -464,7 +464,7 @@ With the same URL as before, the result would be:
{"query":"hello world","sort":"title"}
````

qs supports advanced things such as arrays, nested objects, etc. Check out their [README](https://github.com/ljharb/qs) for more information.
`qs` supports advanced things such as arrays, nested objects, etc. Check out their [README](https://github.com/ljharb/qs) for more information.

## Route transitions

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ The current page is: /books
The querystring is: show=authors,titles&order=1
````

It's important to note that, to keep this component lightweight, svelte-spa-router **does not parse** the "querystring". If you want to parse the value of `$querystring`, you can use third-party modules such as [qs](https://www.npmjs.com/package/qs) in your application.
It's important to note that, to keep this component lightweight, svelte-spa-router **does not parse** the "querystring". If you want to parse the value of `$querystring`, you can use [URLSearchParams](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams) available in all modern browsers, or third-party modules such as [qs](https://www.npmjs.com/package/qs).

### Highlight active links

Expand Down

0 comments on commit 0bceac3

Please sign in to comment.