sveltejs / sveltejs/kit

Document LayoutParams, which differs from RouteParams

Open
#8,581 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

documentation
Dominant language
JavaScript
Stars
20.8k
Forks
2.3k
Avg merge
1d 16h
Merged PRs (30d)
156

Description

Describe the problem

Consider src/routes/[foo]/[bar]/[baz]/+page.svelte route.

In the src/routes/[foo]/[bar]/+layout.ts's load function,

  • params.foo: string
  • params.bar: string
  • params.baz?: string | undefined

params.baz can be accessed, but it is not documented.


Current documentation.

// .svelte-kit/types/src/routes/[foo]/[bar]/[baz]/$types.d.ts

import type * as Kit from '@sveltejs/kit';
 
type RouteParams = {
  foo: string;
  bar: string;
  baz: string;
}
 
export type PageServerLoad = Kit.ServerLoad<RouteParams>;
export type PageLoad = Kit.Load<RouteParams>;

Demo - Consider the following project structure.

.
└── src/
    └── routes/
        └── [foo]/
            └── [bar]/
                ├── [baz]/
                │   └── +page.server.js
                └── +layout.server.js

The following types are generated by SvelteKit. (partially omitted)

// .svelte-kit/types/src/routes/[foo]/[bar]/[baz]/$types.d.ts

import type * as Kit from '@sveltejs/kit';

type RouteParams = { foo: string; bar: string; baz: string }

export type PageServerLoad = Kit.ServerLoad<RouteParams, PageServerParentData, OutputData, RouteId>;
// .svelte-kit/types/src/routes/[foo]/[bar]/$types.d.ts

import type * as Kit from '@sveltejs/kit';

type RouteParams = { foo: string; bar: string }
type LayoutParams = RouteParams & { foo?: string,bar?: string,baz?: string }
// type LayoutParams = { foo: string, bar: string, baz?: string | undefined }

export type LayoutServerLoad = Kit.ServerLoad<LayoutParams, LayoutServerParentData, OutputData, LayoutRouteId>;
Describe the proposed solution

Add documentations to

Alternatives considered

No response

Importance

nice to have

Additional Information

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Generated types and load documentation pages linked in the issue. Compare the documented RouteParams examples with the reported LayoutParams behavior, then explain the distinction using the provided nested-route example. Done means both documentation locations clearly describe which parameters are available to a layout load function.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.