@llms-sdk/router
v2.2.0
Published
Lightweight router with signals integration for LLMS SDK
Maintainers
Readme
@llms-sdk/router
Lightweight router with signals integration for LLMS SDK applications.
Features
- 🔒 Zero vulnerabilities - Custom implementation eliminates CVE-2024-45296
- 📦 Minimal bundle size - <2KB gzipped vs 15KB+ for @vaadin/router
- ⚡ Signal integration - Built with @preact/signals for reactive state
- 🌐 History API - Full browser navigation support
- 🎯 Path parameters - Support for
/users/:idpatterns - 🔍 Query parsing - Automatic URLSearchParams handling
Installation
npm install @llms-sdk/routerQuick Start
import { LLMSRouter } from '@llms-sdk/router';
// Create router instance
const router = new LLMSRouter();
// Add routes
router.addRoute('/users/:id', (route) => {
console.log('User ID:', route.params.id);
});
router.addRoute('/posts/:postId/comments/:commentId', (route) => {
console.log('Post:', route.params.postId, 'Comment:', route.params.commentId);
});
// Start the router
router.start();
// Navigate programmatically
router.navigate('/users/123');
router.navigate('/posts/456/comments/789');API Reference
LLMSRouter
Constructor
new LLMSRouter(config?: RouterConfig)Methods
addRoute(pattern: string, handler: RouteHandler, meta?: any): voidremoveRoute(pattern: string): voidnavigate(path: string, options?: NavigateOptions): voidreplace(path: string, options?: NavigateOptions): voidback(): voidforward(): voidstart(): voidstop(): void
Signals
currentRoute: Signal<Route>- Current route informationparams: Signal<Record<string, string>>- Path parametersquery: Signal<URLSearchParams>- Query parametersisNavigating: Signal<boolean>- Navigation state
Integration with ViewOrchestrator
import { LLMSRouter } from '@llms-sdk/router';
import { setLayoutMode, setStakeholderRole } from './state/multi-view-state.js';
const router = new LLMSRouter();
// Sync layout mode with URL
router.addRoute('/layout/:mode', (route) => {
setLayoutMode(route.params.mode);
});
// Sync stakeholder role with URL
router.addRoute('/role/:role', (route) => {
setStakeholderRole(route.params.role);
});
// Combined routes
router.addRoute('/role/:role/layout/:mode', (route) => {
setStakeholderRole(route.params.role);
setLayoutMode(route.params.mode);
});
router.start();Security
This router is designed to be secure by default:
- No external dependencies with vulnerabilities
- Input validation and sanitization
- XSS prevention through proper escaping
- Content Security Policy compatible
Performance
- Bundle size: <2KB gzipped
- Zero runtime dependencies
- Efficient pattern matching
- Minimal memory footprint
License
MIT
