Function Route

  • Class decorator factory. Applying the Route decorator to a custom element will associate the supplied config with the decorated element constructor. Further, the configured children are iterated over and every child that is a custom element itself will be replaced by its respective route configuration or ignored, if no configuration was associated with the child. Finally, the processed config is added to the Router.

    Type Parameters

    • S extends string

      The Route path string type.

    Parameters

    • config: Assign<{
          children?: (Route<string> | CustomElementConstructor & {
              [route]?: Route<string>;
          })[];
          slots?: Record<string, CustomElementConstructor | CustomElementTagName>;
      }, Omit<Route<S>, "component">> & {
          parent?: Route<string> | CustomElementConstructor & {
              [route]?: Route<string>;
          };
      }

      The Route config for this element.

    Returns (<T>(constructor) => void)

    A class constructor decorator.

      • <T>(constructor): void
      • Type Parameters

        • T extends CustomElementConstructor & {
              [route]?: Route<S>;
          }

        Parameters

        • constructor: T

        Returns void

    Example

    Associate a Route config to a Component:

    import { Component, Route } from '@sgrud/shell';
    import { ChildComponent } from './child-component';

    ⁠@Route({
    path: 'example',
    children: [
    ChildComponent
    ]
    })
    ⁠@Component('example-element')
    export class ExampleComponent extends HTMLElement implements Component {}

    See

    Router

Generated using TypeDoc