Options
All
  • Public
  • Public/Protected
  • All
Menu

Module "router-helper/index"

meiosis-routing/router-helper

The router-helper module contains functions for creating a router by plugging in a router library.

module

routerHelper

Index

Type aliases

RouteFn

RouteFn: (params?: Record<string, any>) => Route

Represents a function that takes params and produces a Route.

Type declaration

    • (params?: Record<string, any>): Route
    • Parameters

      • Optional params: Record<string, any>

      Returns Route

createParsePath

createParsePath: (routeMap: RouteMap, defaultRoute?: Route) => parsePath

Function that creates a function to parse a path.

param

an object with key-value pairs.

param

the default route.

returns

the function that parses a path.

Type declaration

parsePath

parsePath: (path: string, queryParams: Record<string, any>) => Route

Function that parses a path and returns a route.

param

the path to parse.

param

an object with the query string parameters, if any are present.

returns

the route obtained from the path and parameters.

Type declaration

    • (path: string, queryParams: Record<string, any>): Route
    • Parameters

      • path: string
      • queryParams: Record<string, any>

      Returns Route

Functions

convertToPath

  • convertToPath(routeConfig: any, routeOrRoutes: any, qsStringify?: any): string

createFeatherRouter

  • Creates a router using feather-route-matcher.

    example
    
    import createRouteMatcher from "feather-route-matcher";
    import queryString from "query-string"; // only if using query strings
    
    const Route = createRouteSegments([...]);
    
    const routeConfig = { ... };
    
    const router = createFeatherRouter({
      createRouteMatcher,
      routeConfig,
      defaultRoute: [Route.Home()],
      queryString // only if using query strings
    });

    Parameters

    Returns Router

createMithrilRouter

  • Creates a router using Mithril Router.

    example
    
    import m from "mithril";
    // Note: query strings are built-in to Mithril
    
    const Route = createRouteSegments([...]);
    
    const routeConfig = { ... };
    
    const router = createMithrilRouter({
      m,
      routeConfig
    });

    Parameters

    Returns Router

createRouteMap

  • createRouteMap(routeConfig?: {}, path?: string, fn?: (params?: Record<string, any>) => Route, acc?: {}): RouteMap
  • Parameters

    • Default value routeConfig: {} = {}
    • Default value path: string = ""
    • Default value fn: (params?: Record<string, any>) => Route = (_none): Route => []
        • (params?: Record<string, any>): Route
        • Parameters

          • Optional params: Record<string, any>

          Returns Route

    • Default value acc: {} = {}

    Returns RouteMap

createRouter

  • Generic function to create a router from a router library of your choice.

    To use this function, write a createXYZRouter function that in turn calls createRouter. All config parameters except for createParsePath are normally passed-thru from createXYZRouter to createRouter, unless you want to define specific implementations of getPath, setPath, and/or addLocationChangeListener.

    The key parse is createParsePath. This is where you define how to plug in to the router library of your choice.

    function createParsePath(routeMap, defaultRoute) receives a routeMap which is an object with

    example
    
    // Example of a createParsePath function with feather-route-matcher
    const createParsePath = (routeMap, defaultRoute) => {
      const routeMatcher = createRouteMatcher(routeMap);
    
      const parsePath = (path, queryParams) => {
        const match = routeMatcher(path);
    
        if (match) {
          return match.value(Object.assign({}, match.params, queryParams));
        } else {
          return defaultRoute;
        }
      };
      return parsePath;
    };

    Parameters

    Returns Router

    the created router.

createUrlMapperRouter

  • Creates a router using url-mapper.

    example
    
    import Mapper from "url-mapper";
    import urlon from "urlon"; // only if using query strings
    
    const Route = createRouteSegments([...]);
    
    const routeConfig = { ... };
    
    const router = createUrlMapperRouter({
      Mapper,
      routeConfig,
      defaultRoute: [Route.Home()],
      queryString: urlon // only if using query strings
    });

    Parameters

    Returns Router

findPathParams

  • findPathParams(path: string): string[]

findQueryParams

  • findQueryParams(path: string): string[]

setParams

  • setParams(path: string, params: Record<string, any>): string

Generated using TypeDoc