Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dartmoon-io/routerjs
https://github.com/dartmoon-io/routerjs
library
Last synced: 28 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/dartmoon-io/routerjs
- Owner: dartmoon-io
- License: mit
- Created: 2021-08-03T20:44:50.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-08-18T09:58:30.000Z (over 1 year ago)
- Last Synced: 2024-11-02T06:07:28.615Z (about 2 months ago)
- Topics: library
- Language: JavaScript
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Router JS
Only load the JavaScript you want based on the classes of the `body` element of the page.### Installation
```bash
yarn add @dartmoon/routerjs
```or
```bash
npm i @dartmoon/routerjs
```### Usage
```js
import { router } from '@dartmoon/routerjs'router.on('class_name', 'init', () => {
//...
})router.on('class_name', 'finalize', () => {
//...
})
```### Hooks
This library lets you hook your code in different stages of the execution:- `init` your code is executed in the initialization phase
- `finalize` your code is executed after all `init` hooks are executed### Common code
If you need to execute a piece of code on every page you can use the special keyword `common` instead of the class name.```js
import { router } from '@dartmoon/routerjs'router.on('common', 'init', () => {
//...
})router.on('common', 'finalize', () => {
//...
})
```## License
This project is licensed under the MIT License - see the LICENSE.md file for details