question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ordered url params

See original GitHub issue

Describe the problem

It’s currently impossible to have information about the order of url params.

Say i have the following path: /anything/${id}/${otherId}, and i want to display in a breadcrumbs component content related to each id and otherId (for instance a name, fetched from a distant api).

$page.params gives {id, otherId}, which can be used to get a reverse mapping between the slug values in the path and the name of each param, helpful to know what to do with each value (basically fetch data). But what if id and otherId actually are the same value, 1 for instance ? In this case, the reversing mapping would be broken, since we’d get {1: 'otherId'}, and lose the info about id.

Describe the proposed solution

Maybe make an orderedParams available in InputProps and page store.

It would provide [{slug: 'id', value: 1}, {slug: 'otherId', value: 1}], or even just ['id', 'otherId'].

Alternatives considered

Hope all the ids are unique.

Importance

nice to have

Additional Information

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
rmunncommented, Mar 8, 2022

Have you tried doing for (const paramName in Object.keys(params))? I haven’t yet checked the Svelte-Kit source, but I believe the params object will have its keys set in left-to-right order. And while Javascript used to not guarantee the order of iteration, I believe it’s been guaranteed since ES2015 that object properties will be iterated in insertion order. So you might already have the orderedParams that you’re looking for, simply by using Object.keys. It may not be guaranteed in the Svelte-Kit documentation, but it’s very unlikely to change.

0reactions
Rich-Harriscommented, Mar 16, 2022

Correct, the keys will enumerate left-to-right. In any case, https://github.com/sveltejs/kit/pull/4345 will make the routeId available, which solves this problem — closing this

Read more comments on GitHub >

github_iconTop Results From Across the Web

A Beginner's Guide to URL Parameters
URL parameters are commonly used to sort content on a page, making it easier for users to navigate products in an online store....
Read more >
How does position of parameters in a Query string affect ...
A properly written application will find a given query parameter in any order and will not be order sensitive. It is possible though...
Read more >
An SEO Guide to URL Parameter Handling
URL parameters create duplicate content, waste crawl budget, and dilute ranking signals. Learn six ways to avoid potential SEO issues with ...
Read more >
Query string - Wikipedia
A query string is a part of a uniform resource locator (URL) that assigns values to specified parameters. A query string commonly includes...
Read more >
Populate Order Information with the URL
Use URL parameters to populate transaction information in your customer's order session. Parameters are values that the SBL passes as part of the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found