missing params if route contains errors
See original GitHub issueDescribe the bug
If a route contains an error (unhandled fetch-requests, errors in a component, etc.) then the __error.svelte
file gets rendered.
This will also call the load
function from the __layout.svelte
file, like a normal request would do. Except that the params
object is empty.
In a production application I use the slug to get the locale from the url e.g. /en/settings
. When something fails then I no longer have the locale information in the params
object and I need to use a workaround to get the locale.
const lang = params.lang || url.pathname.split('/')[1]
In this case it’s simple and I know the position of the param, but for other cases it would be good if the params
could also be accessed when a error
page is rendered.
Reproduction
Here is a demo repository with a short description in the README.md
:
https://github.com/ivanhofer/sveltekit-missing-params
Logs
No response
System Info
System:
OS: Linux 5.10 Ubuntu 20.04.3 LTS (Focal Fossa)
CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-11370H @ 3.30GHz
Memory: 2.63 GB / 7.66 GB
Container: Yes
Shell: 5.8 - /usr/bin/zsh
Binaries:
Node: 16.13.1 - ~/.volta/tools/image/node/16.13.1/bin/node
Yarn: 1.22.17 - ~/.volta/tools/image/yarn/1.22.17/bin/yarn
npm: 8.1.2 - ~/.volta/tools/image/node/16.13.1/bin/npm
npmPackages:
@sveltejs/adapter-auto: next => 1.0.0-next.17
@sveltejs/kit: next => 1.0.0-next.251
svelte: ^3.44.0 => 3.46.3
Severity
serious, but I can work around it
Additional Information
No response
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:5 (4 by maintainers)
Since #4344,
params
are available in error pages: https://stackblitz.com/edit/sveltejs-kit-template-default-h6by79?file=src%2Froutes%2Findex.svelte&terminal=dev@Badlapje thanks for taking the time! Yeah Im applying the workaround.