nanorouter-ts
v1.0.2
Published
Lightweight TypeScript router for browser and Node.js
Maintainers
Readme
Features
- Lightweight and minimal
- TypeScript support
- Route parameters
- Simple API
- Browser & Node.js support
Installation
NPM
npm install nanorouter-tsCDN
<!-- Latest version -->
<script src="https://unpkg.com/nanorouter-ts/dist/umd/nanorouter.min.js"></script>
<!-- Specific version -->
<script src="https://unpkg.com/[email protected]/dist/umd/nanorouter.min.js"></script>Usage
ES Modules / TypeScript
import { createRouter } from 'nanorouter-ts';
const router = createRouter();
router.on('/', () => console.log('Home'));Browser (UMD)
<script src="https://unpkg.com/nanorouter-ts/dist/umd/nanorouter.min.js"></script>
<script>
const router = NanoRouter.createRouter();
router.on('/', () => console.log('Home'));
</script>API
createRouter()
Creates a new router instance.
router.on(path: string, handler: RouteHandler)
Registers a route handler for the specified path.
router.emit(path: string)
Triggers the handler for the matching route.
License
MIT
Author
Contributing
- Fork it
- Create your feature branch (
git checkout -b feature/my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin feature/my-new-feature) - Create new Pull Request
