@daucus/router
TypeScript icon, indicating that this package has built-in type declarations

0.4.1 • Public • Published

@daucus/router

Router for Daucus Web Apps

📖 Documentation

@daucus/router provides 3 differents solutions to help you use the routes generated by the Daucus CLI (routes.js):

  1. a simple daucus-router Web Component
  2. a programmatic router
  3. route matching functions, for custom routing33

Usage Examples

Programmatic API

The DaucusRouter class provides a default implementation of the @modern-helpers/router AbstractRouter for Daucus.

import { DaucusRouter } from "@daucus/router";
// routes generated by the Daucus CLI
import daucusRoutes from "./_daucus_/routes.js";

const appRouter = new DaucusRouter();
appRouter.run(daucusRoutes, "/the-default-path/", "/base/directory");

For more advanced use cases, use the routeFinder and i18nRouteFinder functions to match a path with a Daucus route.

import { routeFinder } from "@daucus/router";
// routes generated by the Daucus CLI
import daucusRoutes from "./_daucus_/routes.js";

const daucusRouteFinder = routeFinder(daucusRoutes);

// custom routing
function myCustomRouter() {
  //...
  if (path.startsWith("/docs/")) {
    const daucusRoute = daucusRouteFinder(path);
    //...
  }
}

For now, building a custom router is mandatory when using the i18n option with the Daucus CLI.

import { i18nRouteFinder } from "@daucus/router";
// routes generated by the Daucus CLI (with "i18n": true)
import daucusRoutes from "./_daucus_/routes.js";

const daucusRouteFinder = i18nRouteFinder(daucusRoutes);

// custom routing
function myCustomRouter() {
  //...
  if (path.startsWith("/docs/")) {
    const daucusRoute = daucusRouteFinder(path, lang);
    //...
  }
}

Web Components

daucus-router

Routing wrapper element for Daucus Routes

Wrap the programmatic DaucusRouter for declarative usage.

Properties

Property Attribute Type Default Description
baseDir base-dir string "templates/" Directory where templates are published, relative to the baseHRef (should end with a '/')
defaultPath default-path string "/docs/" Path of the default route
routes `SimpleRoutesConfig undefined`

Events

Event Description
navigation-end A navigation ended without error
navigation-start New navigation begins
project-change A navigation led to a route from another Daucus Project
route-match A corresponding route was found for a navigation
route-redirection A navigation led to a redirection to another route

Readme

Keywords

none

Package Sidebar

Install

npm i @daucus/router

Weekly Downloads

1

Version

0.4.1

License

MIT

Unpacked Size

63.4 kB

Total Files

36

Last publish

Collaborators

  • noelmace