Router object containing callback registration methods and utilities for navigating and managing routes.

Constructors

Accessors

  • get params(): {
        [key: string]: string;
    }
  • Get the URL parameters extracted from the current route and path.

    Returns {
        [key: string]: string;
    }

    URL parameters for the current route.

    • [key: string]: string
  • get path(): string
  • Get the current URL path.

    Returns string

    The current path from location.pathname

Methods

  • Add a callback that will be called after new HTML content is injected onto the page.

    Parameters

    • fn: Function

      Function that will be called after injection.

    Returns Router

    Returns the router.

  • Add a callback that will be called after navigating to new URL path.

    Parameters

    • fn: Function

      Function that will be called after navigation.

    Returns Router

    Returns the router.

  • forward Navigate to the next history entry.

    Returns void

  • Check if the route matches the current URL path, or specified URL path.

    Parameters

    • route: string

      Route string.

    • to: string = location.pathname

      Path string to check if matches the route. Defaults to the current URL path.

    Returns boolean

    Whether the path matches the route string.

  • Navigate to a new URL path on the site and push the state to the history stack.

    Parameters

    • path: string

      URL path to navigate to.

    Returns void

  • Navigate to a new URL path on the site and replace the state to the history stack.

    Parameters

    • path: string

      URL path to navigate to.

    Returns void