1.0.1 • Published 3 years ago

@bukunmikuti/view-router v1.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

View Router

NPM

npm i @bukunmikuti/view-router

Script include

<script src="https://unpkg.com/@bukunmikuti/view-router"></script>

ES Module

import ViewRouter from "https://cdn.skypack.dev/@bukunmikuti/view-router"

Instantiate the class by passing an object parameter which must include views: [] and other optional properties.

const viewrouter = new ViewRouter({
	views: [], //required
	navigation: "history"||"hash",
	transition: true||false, 
})

views: []

Type: Array of objects — required Description: This property stores each view's property in an object. It can contain several view definitions.

const viewrouter = new ViewRouter({
	views: [
		{
			id: "login", //required
			path: "/login",
			origin: "/login.html",
			mounted() {}, //callback
			render() {} //callback
		},
		
		{/* another view */}
		{/* another view */}
	]
})

A view definition should include the following properties:

View propertyDescriptionDefault Value
idThe 'id' attribute of the template tag — Requiredundefined
pathThe URL path that triggers the view when navigated to.undefined
originIf the view is located in another html document, this will contain the relative path to the document.undefined
mountedViews are not part of the DOM by default, they only get mounted when routed to for the first time. Put any logic that depends on accessing elements of the view here. It is called only oncecallback undefined
renderThis method is called each time a view is routed tocallback undefined

navigation

Type: String — history or hash (optional) Description: Use hash navigation or Web history API. If undefined or false then routing is automatically disabled, else views: [{path: ""}] must be specified.

transition

Type: Boolean — optional Description: Enable or disable view transitions. Transition type must be specified on the view <template> tag. All transitions — fadeIn fadeInTop fadeInBottom fadeInLeft fadeInRight

<!--index.html-->
<template id="login" class="v-router fadeInLeft"></template>

<script type="module">
import ViewRouter from "..."

let v = new ViewRouter({
 //...
 transition: true
})
</script>

Methods

MethodDescriptionReturn Value
routeTo()Navigate to the specified view. Accepts view id as parameterexecutes render()

Contribution

You can contribute by making pull requests to fix issues, dropping a code review/demo example or updating the readme. Your changes should be clearly stated. Thank you!

License

This project is available under the ISC Liscense