Options
All
  • Public
  • Public/Protected
  • All
Menu

solid-typefu-router5 - v1.4.0

Index

Type Aliases

LinkNav<Route>: { params?: undefined; to: "@@back" | "@@forward" } | (Route extends { name: infer Name; params: infer Params } ? { 0: { params?: Params; to: Name }; 1: { params: Params; to: Name } }[RequiresParams<Params>] : never)

Type Parameters

LinkProps<Route>: O.Merge<Omit<JSX.IntrinsicElements["a"], "onClick">, { children?: JSX.Element; disabled?: boolean; display?: "button"; nav?: boolean; navIgnoreParams?: boolean; openInNewTab?: boolean; back?: any; forward?: any; navActiveClassList?: any; onClick?: any } & LinkNav<Route>>

Props for making a Link component.

remarks

You can set default values for any link props using the defaultLinkProps option in the initial configuration.

Type Parameters

MatchRouteProps: PathProps & { children: JSX.Element }
ParseParams<Path>: String.Split<Path, "/"> extends infer Segs ? Any.Compute<Union.IntersectOf<ParseSeg<Segs[keyof Segs]>>> : never

Parse a router5 path into its params

Type Parameters

  • Path extends string

RSM<RM, Path>: Path extends string ? Object.Path<_RSM0<RM>, String.Split<Path, ".">> : Path extends string[] ? Object.Path<_RSM0<RM>, Path> : _RSM0<RM>

Type Parameters

  • RM extends [...RouteMeta[]]

  • Path extends string[] | string | undefined = undefined

ReadRoutes<Tree>: _RouteQueue<Tree> extends infer Q ? _ReadRoutesQueue<Q> : never

Takes your routes and produces type metadata for consumption in this library. The result is an array of RouteMeta, one for each route.

Type Parameters

RenderNodeLike: RouterRenderNode<any>
RenderTreeLike: RenderNodeLike & {}
RouteLike: string
RouteTreeLike: readonly RouteNodeLike[]
RouterFallbackRenderFn<Params>: ((props: { params: Params }) => JSX.Element)

Type Parameters

  • Params = {}

Type declaration

    • (props: { params: Params }): JSX.Element
    • Parameters

      • props: { params: Params }
        • params: Params

      Returns JSX.Element

RouterRenderFn<Params>: ((props: { children?: JSX.Element; params: Params }) => JSX.Element)

Type Parameters

  • Params = {}

Type declaration

    • (props: { children?: JSX.Element; params: Params }): JSX.Element
    • Parameters

      • props: { children?: JSX.Element; params: Params }
        • Optional children?: JSX.Element
        • params: Params

      Returns JSX.Element

RouterRenderNode<Params>: { fallback?: RouterFallbackRenderFn<Params>; render?: RouterRenderFn<Params> }

Tells solid-typefu-router5 how to render a node if the path leading to it matches the current route name.

Type Parameters

  • Params = {}

Type declaration

  • Optional fallback?: RouterFallbackRenderFn<Params>

    Fallback children to use if none are available to give to render. Default: nothing

  • Optional render?: RouterRenderFn<Params>

    Defaults to rendering the children.

RoutesLike<Deps>: readonly Object.Readonly<Route<Deps>, Any.Key, "deep">[]

Type Parameters

  • Deps

ShowRouteProps: MatchRouteProps & { fallback?: JSX.Element }

Variables

Context: Context<undefined | RouterContextValue<any, any, any>> = ...

Functions

  • SwitchRoutes(props: { children: MatchRouteProps[]; fallback?: Element }): JSX.Element
  • default<Routes, RM, Deps>(config: RouterConfig<Deps, Routes, RM>): SolidRouter<Deps, RM>
  • Create a router for use in solid-js.

    I'd recommend putting your router in its own file like './router.ts', then exporting the results of this function, like

    import { createRouter, Router as Router5 } from 'router5';
    import { createSolidRouter } from 'solid-ts-router';

    const routes = [
    ...
    ] as const;

    // note the "as const" is very important! this causes TypeScript to infer
    // `routes` as the narrowest possible type.

    function createRouter5(routes: Route<Deps>[]): Router5 {
    return createRouter(...)
    }

    function onStart(router: Router5): void {
    // initial redirect here
    ...
    }

    export const { Provider, Link, Router } = createSolidRouter({ routes, createRouter5, onStart });

    Type Parameters

    • Routes extends readonly { canActivate?: ReadonlyDeep<undefined | ActivationFnFactory<Deps>>; children?: ReadonlyDeep<undefined | Route<Deps>[]>; defaultParams?: ReadonlyDeep<undefined | Params>; forwardTo?: ReadonlyDeep<undefined | string>; name: string; path: string; decodeParams?: any; encodeParams?: any }[]

    • RM extends []

    • Deps = DefaultDependencies

    Parameters

    • config: RouterConfig<Deps, Routes, RM>

    Returns SolidRouter<Deps, RM>

  • Find whether 'link' is an ancestor of, or equal to, 'here'

    Maybe useful for creating your own Link component.

    Type Parameters

    • Link extends string

    Parameters

    • here: string
    • link: Link

    Returns RouteActive

  • useIsActive<Link>(link: Link, params?: Record<string, any>, paramsIsEqual?: ((a: undefined | Record<string, any>, b: undefined | Record<string, any>) => boolean)): (() => RouteActive)
  • Type Parameters

    • Link extends string

    Parameters

    • link: Link
    • Optional params: Record<string, any>
    • paramsIsEqual: ((a: undefined | Record<string, any>, b: undefined | Record<string, any>) => boolean) = paramsEq
        • (a: undefined | Record<string, any>, b: undefined | Record<string, any>): boolean
        • Parameters

          • a: undefined | Record<string, any>
          • b: undefined | Record<string, any>

          Returns boolean

    Returns (() => RouteActive)

Generated using TypeDoc