Skip to content

Unify all parameters of the children snippet of the Route and Router components under a single context object #74

@webJose

Description

@webJose

Motivation

As features are added, the list of children parameters might grow too. It is better to move to a single "contextual" parameter.

Technical Details

Create the RouterContext and RouteContext types:

export type RouterContext {
  state: any;
  rs: RouteStatus;
}

export type RouteContext = RouterContext & {
  rp?: Record<string, ParameterValue>;
}

Then work the Router and Route components to group the parameter values into a single object that is passed to the rendering of the children snippet. This single contextual parameter should be destructurable to allow for easy syntax:

<Router>
  {#snippet children({ state, rs })}
    ...
    <Route ...>
      {#snippet children({ state, rs, rp })}
        ...
      {/snippet}
    </Route>
    ...
  {/snippet}
</Router>

NOTE TO READERS: Yes, the state and rs values in the Router and child Route are the same thing, so in practice, you could just deconstruct for route parameters in the children snippet for Route components: {#snippet children({ rp })}.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Priority: MediumMedium priority. Upvote to request a higher priority. Downvote to attempt to lower priority.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions