0.1.16 • Published 7 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