sveltejs / kit

web development, streamlined
https://kit.svelte.dev
MIT License
18.4k stars 1.88k forks source link

Route under multiple optional parameters is not matched correctly in every case #10712

Open popapaul opened 12 months ago

popapaul commented 12 months ago

Describe the bug

In case of the following route structure:

The following links will go correctly to Program route:

But /2022/program ✘ will instead go to Content route, practically turning the optional parameter culture into a required parameter when year is set which is not in my opinion the expected behaviour

  1. Content route as rest parameter:

    Expected behaviour:

Actual behaviour:

Additionally

When changing /[[culture=culture]]/[[year=year]]/[...content] to /[[culture=culture]]/[[year=year]]/[content],

The following links will go correctly to Content route:

But

will both be met by 404 Not Found.

  1. Content route as parameter:

Expected behaviour:

/2022/program -> Program route /2022/content -> Content route

Actual behaviour:

/2022/program -> 404 /2022/content -> 404

Reproduction

Stackblitz Reproduction

Logs

No response

System Info

System:
    OS: Windows 10 10.0.22621
    CPU: (12) x64 AMD Ryzen 5 3600 6-Core Processor
    Memory: 17.48 GB / 31.93 GB
  Binaries:
    Node: 18.16.0 - C:\Program Files\nodejs\node.EXE
    npm: 9.5.1 - C:\Program Files\nodejs\npm.CMD
    pnpm: 8.6.0 - C:\Program Files\nodejs\pnpm.CMD
  Browsers:
    Edge: Spartan (44.22621.2134.0), Chromium (116.0.1938.76)
    Internet Explorer: 11.0.22621.1
  npmPackages:
    svelte: ^4.2.0 => 4.2.0

Severity

serious, but I can work around it

Additional Information

No response

allozaur commented 6 months ago

I've also encountered this issue in my project that's using "@sveltejs/kit": "^2.0.0"" and "svelte": "^4.2.7"".

[!NOTE] This issue only persists if the Level 1 route (lang param) is optional. If it's a required level route, then the problem goes away. Alternatively it also works when lang route is optional, but when instead of [explore=explore] we use hardcoded value for this route level.

Not working

My structure looks like this:

Routes that are working:

Routes that are returning 404:

Working