RouterConfig

Pass a RouterConfig object to the createRouter() API to create a router for specific routes.

Properties

Property Type Required/Optional Description
routes Array Optional An array of route definitions. If you don't specify a RouteDefinition array, the default value is an empty array. If you don't specify a value for RouterConfig.routes, the router can't match any locations.
basePath String Optional A path prefix applied to all URIs for the router. If you don't specify a base path, the default value is "".
caseSensitive Boolean Optional If true, URIs are processed case sensitively. The default value is false.
i18n Array Optional An i18n config that may affect the path prefix applied to all URIs. The default value is {locale: 'en-US', defaultLocale: 'en-US'}.

Syntax

type RouterConfig = {
  routes?: RouteDefinition[],
  basePath?: string,
  caseSensitive?: boolean,
  i18n?: {
    locale: string;
    defaultLocale: string;
  },
};

Example

routes: [
    {
      id: 'home',
      uri: '/'
      handler: () => import('example/homePageHandler'),
        page: {
            type: 'home',
        },
    },
    {
        id: 'namedPage',
        uri: '/:pageName',
        handler: () => import('example/namedPageHandler'),
        page: {
            type: 'namedPage',
            attributes: {
                pageName: ':pageName',
            },
        },
    }
  ],
  basePath: '/my-site',
  i18n: {
    locale: 'es',
    defaultLocale: 'en-US'
  },
  caseSensitive: true