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.

Rest Route Params "Stealing" Previous Dynamic Segment Param

See original GitHub issue

Describe the bug Adding rest route params appears to steal some of previous dynamic segment parameter

This would prevent the route shown in the docs from working

/[org]/[repo]/tree/[branch]/[...file] would only get the first character for the [branch] param.

Example:

Given a route structure containing:

/fixed/index.svelte

<script>
  import { page } from '$app/stores'
</script>

<p>/fixed</p>
<pre>{JSON.stringify($page, null, '  ')}</pre>

/fixed/[dynamic]/index.svelte

<script>
  import { page } from '$app/stores'
</script>

<p>/fixed/[dynamic]</p>
<pre>{JSON.stringify($page, null, '  ')}</pre>

/fixed/[dynamic]/[…rest].svelte

<script>
  import { page } from '$app/stores'
</script>

<p>/fixed/[dynamic]/[...rest]</p>
<pre>{JSON.stringify($page, null, '  ')}</pre>

… works as expected until the rest route is reached, for example:

http://localhost:3000/fixed

/fixed

{
  "host": "localhost:3000",
  "path": "/fixed",
  "query": {},
  "params": {}
}

http://localhost:3000/fixed/one

/fixed/[dynamic]

{
  "host": "localhost:3000",
  "path": "/fixed/one",
  "query": {},
  "params": {
    "dynamic": "one"
  }
}

http://localhost:3000/fixed/one/two/three

/fixed/[dynamic]/[...rest]

{
  "host": "localhost:3000",
  "path": "/fixed/one/two/three",
  "query": {},
  "params": {
    "dynamic": "o",
    "rest": "ne/two/three"
  }
}

Note the “dynamic” parameter which is now o with the rest parameter stealing the ne

I also tried using /[...rest]/index.svelte as well (same result)

To Reproduce Example repo: https://github.com/CaptainCodeman/svelte-kit-rest-routing

Expected behavior I expected the final route to produce:

{
  "host": "localhost:3000",
  "path": "/fixed/one/two/three",
  "query": {},
  "params": {
    "dynamic": "one",
    "rest": "/two/three"
  }
}

Information about your SvelteKit Installation:

Diagnostics

System: OS: macOS 11.2.3 CPU: (8) x64 Intel® Core™ i7-4850HQ CPU @ 2.30GHz Memory: 1.25 GB / 16.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 14.15.1 - /usr/local/bin/node npm: 7.8.0 - /usr/local/bin/npm Browsers: Chrome: 89.0.4389.114 Firefox: 83.0 Safari: 14.0.3 npmPackages: @sveltejs/kit: next => 1.0.0-next.71 svelte: ^3.29.0 => 3.37.0 vite: ^2.1.0 => 2.1.5

  • Your browser Chrome 89

  • Your adapter (e.g. Node, static, Vercel, Begin, etc…)

  • Node

Severity No immediate urgency

Additional context The dynamic segment is the context for a selected project, the rest parameters are a folder path in the context of the app.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
Rich-Harriscommented, Apr 19, 2021

closed via #1128, thanks

1reaction
rmunncommented, Apr 20, 2021

It’s been released now, and I can confirm that it fixes the bug. I took my bug reproduction project, ran pnpm update in it to pull in Svelte-Kit version 1.0.0-next.84 and the localhost:3000/one-food/two-foo/three route now returns a 404 as it should.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Routing: Spread segments can match in the middle of ... - GitHub
Describe the bug Routes with [...spread] segments can match in the ... Rest Route Params "Stealing" Previous Dynamic Segment Param #918.
Read more >
Best practices for REST API design - Stack Overflow Blog
Learn how to design REST APIs to be easy to understand for anyone, future-proof, secure, and fast since they serve data to clients...
Read more >
RESTful parameters antipattern considerations for queries ...
RESTful API developers should be concerned with the two main parts of a URL: the path and the query. RESTful URL Location of...
Read more >
REST API Design Best Practices for Parameter and Query ...
Best practices for parameter and query string usage in REST APIs. ... Parameters that are highly dynamic, especially when they're only valid ...
Read more >
How to differentiate similar looking path parameters in ...
I am looking for the most elegant way to design the endpoint that has these params as a part of the dynamic URL...
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