Skip to content

Document LayoutParams, which differs from RouteParams #8581

@hyunbinseo

Description

@hyunbinseo

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions