Only load the JavaScript you want based on the classes of the body
element of the page.
yarn add @dartmoon/routerjs
or
npm i @dartmoon/routerjs
import { router } from '@dartmoon/routerjs'
router.on('class_name', 'init', () => {
//...
})
router.on('class_name', 'finalize', () => {
//...
})
This library lets you hook your code in different stages of the execution:
init
your code is executed in the initialization phasefinalize
your code is executed after allinit
hooks are executed
If you need to execute a piece of code on every page you can use the special keyword common
instead of the class name.
import { router } from '@dartmoon/routerjs'
router.on('common', 'init', () => {
//...
})
router.on('common', 'finalize', () => {
//...
})
This project is licensed under the MIT License - see the LICENSE.md file for details