0.1.16 • Published 11 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
11 months ago
0.1.15
12 months ago
0.1.14
12 months ago
0.1.13
12 months ago
0.1.12
12 months ago
0.1.11
12 months ago
0.1.10
12 months ago
0.1.9
12 months ago
0.1.8
12 months ago
0.1.7
12 months ago
0.1.6
12 months ago
0.1.5
12 months ago
0.1.4
12 months ago
0.1.3
1 year ago
0.1.2
1 year ago
0.1.1
1 year ago
0.1.0
1 year ago