0.1.16 • Published 7 months ago

@coloco/router v0.1.16

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

@coloco/router

A routing library for Coloco applications.

Installation

npm install @coloco/router

Usage

import { Router } from '@coloco/router';

// Define your routes
const routes = [
  { path: '/', component: HomeComponent, exact: true },
  { path: '/users', component: UsersComponent },
  { path: '/about', component: AboutComponent, exact: true },
];

// Create a router instance
const router = new Router({
  routes,
  defaultRoute: '/'
});

// Navigate to a path
const route = router.navigate('/users/123');

// Render the component
if (route) {
  renderComponent(route.component);
}

API

Router

The main router class.

Constructor

constructor(options: RouterOptions)
  • options.routes: An array of route objects
  • options.defaultRoute: The default route to navigate to when no match is found (default: '/')

Methods

navigate(path: string): Route | null

Navigate to a specific path and return the matching route.

Route

An interface representing a route.

  • path: The path to match
  • component: The component to render
  • exact: Whether the path should match exactly (default: false)

License

MIT

0.1.16

7 months ago

0.1.15

8 months ago

0.1.14

8 months ago

0.1.13

8 months ago

0.1.12

8 months ago

0.1.11

8 months ago

0.1.10

8 months ago

0.1.9

8 months ago

0.1.8

8 months ago

0.1.7

8 months ago

0.1.6

8 months ago

0.1.5

8 months ago

0.1.4

8 months ago

0.1.3

8 months ago

0.1.2

8 months ago

0.1.1

8 months ago

0.1.0

8 months ago