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

Route params is empty if page not found (404) #6453

Closed
bjon opened this issue Aug 30, 2022 · 1 comment
Closed

Route params is empty if page not found (404) #6453

bjon opened this issue Aug 30, 2022 · 1 comment

Comments

@bjon
Copy link
Contributor

bjon commented Aug 30, 2022

Describe the bug

We have a setup like this: /[lang]/path1, /[lang]/path2, etc...

In layout.ts we get the lang from params, so we can fetch other stuff.
But when a page is not found, params is now an empty object.
This broke in v432 (#6174)

Reproduction

  • npm create svelte@latest repro-6453
  • create route src/routes/[test]
  • move +page into src/routes/[test]
  • add +layout.ts to src/routes
/** @type {import('./$types').LayoutLoad} */
export function load({ params }) {
  console.info("params", params);
}

Logs

No response

System Info

System:
    OS: Linux 5.10 Ubuntu 20.04.5 LTS (Focal Fossa)
    CPU: (24) x64 AMD Ryzen 9 3900X 12-Core Processor
    Memory: 12.22 GB / 15.59 GB
    Container: Yes
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 16.17.0 - /usr/bin/node
    npm: 8.15.0 - /usr/bin/npm

Severity

blocking an upgrade

Additional Information

No response

@Rich-Harris
Copy link
Member

This is expected behaviour — if no route matched, there's no route to extract params from. You'll need to use a rest route as described here: https://kit.svelte.dev/docs/advanced-routing#rest-parameters

// src/routes/[test]/[...catchall]/+page.js
import { error } from '@sveltejs/kit';

export function load() {
  throw error(404);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants