0.1.16 • Published 8 months ago
@coloco/router v0.1.16
@coloco/router
A routing library for Coloco applications.
Installation
npm install @coloco/routerUsage
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 objectsoptions.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 matchcomponent: The component to renderexact: Whether the path should match exactly (default: false)
License
MIT
0.1.16
8 months ago
0.1.15
9 months ago
0.1.14
9 months ago
0.1.13
9 months ago
0.1.12
9 months ago
0.1.11
9 months ago
0.1.10
9 months ago
0.1.9
9 months ago
0.1.8
9 months ago
0.1.7
9 months ago
0.1.6
9 months ago
0.1.5
9 months ago
0.1.4
9 months ago
0.1.3
10 months ago
0.1.2
10 months ago
0.1.1
10 months ago
0.1.0
10 months ago