Only load the JavaScript you want based on the classes of the body element of the page.
yarn add @dartmoon/routerjsor
npm i @dartmoon/routerjsimport { 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:
inityour code is executed in the initialization phasefinalizeyour code is executed after allinithooks 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