request.params not available in handle hook as docs / types indicate
See original GitHub issueDescribe the bug
Request.params
is null
in handle
hook.
Logs
To Reproduce
- Create a route that uses params, e.g.
src/routes/[product]/index.svelte
- Create a hook with
handle
function located atsrc/hooks.ts
- Try to access
request.params
inhandle
function
Example repo: https://github.com/RaeesBhatti/svelte-params-bug
Expected behavior
request.params
should be available in handle
function of hooks.
Stacktraces
Information about your SvelteKit Installation:
Diagnostics
System:
OS: macOS 11.2.3
CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 535.77 MB / 32.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 14.8.0 - /usr/local/bin/node
Yarn: 1.22.10 - /usr/local/bin/yarn
npm: 6.14.7 - /usr/local/bin/npm
Browsers:
Chrome: 90.0.4430.85
Safari: 14.0.3
Safari Technology Preview: 14.2
npmPackages:
@sveltejs/kit: next => 1.0.0-next.87
svelte: ^3.29.0 => 3.37.0
-
Your browser: Safari Version 14.0.3 (16610.4.3.1.7)
-
Your adapter: Cloudflare Worker but this issues comes up even in
dev
mode.
Severity Blocking usage of SvelteKit because I need params to fetch the right data from database.
Additional context
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:10 (5 by maintainers)
Top Results From Across the Web
How can I get (query string) parameters from the URL in Next.js?
Method #1: SSR (Server-Side Rendering): You should use Query Context for that page. The reason is that: this data cannot be pre-rendered ahead...
Read more >Hooks - Apollo GraphQL Docs
Apollo Client react hooks API reference. ... Param, Type, Description ... Client's React integration, and it is not available in the core ApolloClient...
Read more >Query Parameters - Routing - Ember Guides
Query parameters are optional key-value pairs that appear to the right of the ? in a URL. For example, the following URL has...
Read more >Parameter Binding in ASP.NET Web API - ASP.NET 4.x
In this example, the content type is "application/json" and the request body is a raw JSON string (not a JSON object). At most...
Read more >use-query-params - npm
React Hook for managing state in URL query parameters with easy ... TypeScript icon, indicating that this package has built-in type ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
What’s the current recommended way to deal with this? I have a bunch of endpoints with an
[id]
param and I need to short-circuit them and return an error if the param is not in a valid format. I was hoping to do it inhandle
but it looks like I need to add this boilerplate to every handler (get
,post
,del
, etc.) of every endpoint. Is there no better way? The only way I can think of is to write a function that wraps every handler, so:I suppose this is workable but seems pretty clunky.
See related discussion on param validators here: https://github.com/sveltejs/kit/issues/4291