All Projects → reneviering → Vanilla Ui Router

reneviering / Vanilla Ui Router

Licence: mit
Simple vanilla JavaScript router

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Vanilla Ui Router

Vanillajs Spa
a simple SPA in vanilla js
Stars: ✭ 265 (+530.95%)
Mutual labels:  spa, vanilla-js, vanilla-javascript, single-page-app
CRUD-Laravel-Livewire-SPA
CRUD Laravel 7 & Livewire (SPA) Single Page Application
Stars: ✭ 34 (-19.05%)
Mutual labels:  spa, single-page-app, single-page-applications
laravel-vue-starter
Well Documented Laravel Starter App From Development to Production. For Full Blown RESTFUL API and SPA with Beautiful UI Using Buefy / ElementUi For Reusable Vue Components
Stars: ✭ 80 (+90.48%)
Mutual labels:  spa, single-page-app, single-page-applications
Abstract State Router
Like ui-router, but without all the Angular. The best way to structure a single-page webapp.
Stars: ✭ 288 (+585.71%)
Mutual labels:  router, spa, single-page-app
Universal Router
A simple middleware-style router for isomorphic JavaScript web apps
Stars: ✭ 1,598 (+3704.76%)
Mutual labels:  router, spa, single-page-app
curved-menu
VanillaJS fully configurable curved menu (circular navigation)
Stars: ✭ 30 (-28.57%)
Mutual labels:  vanilla, vanilla-javascript, vanilla-js
Bunny
BunnyJS - Lightweight native (vanilla) JavaScript (JS) and ECMAScript 6 (ES6) browser library, package of small stand-alone components without dependencies: FormData, upload, image preview, HTML5 validation, Autocomplete, Dropdown, Calendar, Datepicker, Ajax, Datatable, Pagination, URL, Template engine, Element positioning, smooth scrolling, routing, inversion of control and more. Simple syntax and architecture. Next generation jQuery and front-end framework. Documentation and examples available.
Stars: ✭ 473 (+1026.19%)
Mutual labels:  vanilla-js, vanilla-javascript, vanilla
Laravel Vue Starter
Well Documented Laravel Starter App From Development to Production. For Full Blown RESTFUL API and SPA with Beautiful UI Using Buefy / ElementUi For Reusable Vue Components
Stars: ✭ 76 (+80.95%)
Mutual labels:  spa, single-page-app, single-page-applications
bs-breakpoints
A plugin which detect Bootstrap 4 breakpoints and emit when there is a change
Stars: ✭ 22 (-47.62%)
Mutual labels:  vanilla-javascript, vanilla-js, vanillajs
vanillajs-hello
Start a VanillaJS website using WebPack in just 30 seconds: HTML,CSS,Babel,SASS,Bootstrap,Prettier,Gitpod
Stars: ✭ 24 (-42.86%)
Mutual labels:  vanilla-javascript, vanilla-js, vanillajs
Erlach
☣⚫⚫ SPA Imageboad on WebSockets written on Erlang
Stars: ✭ 23 (-45.24%)
Mutual labels:  spa, single-page-app, single-page-applications
Router.js
Router.js is a simple and powerful javascript library to handle routing
Stars: ✭ 107 (+154.76%)
Mutual labels:  router, vanilla-js, vanilla-javascript
Knockout Spa
A mini but full-fledged SPA framework and boilerplate to build SPAs fast and scalable
Stars: ✭ 145 (+245.24%)
Mutual labels:  spa, single-page-app, single-page-applications
tensorflowjs-remove-background
Remove Background from the picture using WebAssembly & TensorFlow.js
Stars: ✭ 79 (+88.1%)
Mutual labels:  vanilla-javascript, vanilla-js, vanillajs
Vue Soundcloud
🎧 A SoundCloud client built with Vue and Nuxt
Stars: ✭ 141 (+235.71%)
Mutual labels:  spa, single-page-app, single-page-applications
peasy-js-samples
Showcases business logic built with peasy-js and consumed by multiple clients
Stars: ✭ 19 (-54.76%)
Mutual labels:  spa, single-page-app, single-page-applications
Vanillajs Deck
A Vanilla.js Single Page App (SPA) slide deck for a presentation about Vanilla.js written with no frameworks.
Stars: ✭ 119 (+183.33%)
Mutual labels:  vanilla-js, vanilla-javascript, vanillajs
Bs Custom File Input
A little plugin for Bootstrap 4 custom file input
Stars: ✭ 162 (+285.71%)
Mutual labels:  vanilla-js, vanilla-javascript, vanillajs
wordpress-svelte
Frontend writen on svelt
Stars: ✭ 17 (-59.52%)
Mutual labels:  spa, single-page-app, single-page-applications
Bs Stepper
A stepper for Bootstrap 4.x
Stars: ✭ 261 (+521.43%)
Mutual labels:  vanilla-js, vanilla-javascript, vanillajs

npm version Build Status Coverage Status Code Climate devDependency Status Unicorn

Vanilla UI Router

Greenkeeper badge

Simple vanilla JavaScript router to be used inside a single page app to add routing capabilities.

The router comes with zero dependencies and can be used with any other libraries. It's based on the hashchange-Event.

Installation

$ npm install --save vanilla-ui-router

As UMD module this runs everywhere (ES6 modules, CommonJS, AMD and with good ol’ globals).

Usage

Let's assume your initial markup has the following structure:

<!DOCTYPE html>
<html>
<head>
	<link rel="stylesheet" type="text/css" href="styles.min.css" />
</head>
<body>

	<!-- Entry point, dynamic content is rendered into this DOM element -->
	<main id="app"></main>

	<!-- Bundle where your JavaScript logic lives, even the router configuration -->
	<script src="bundle.js"></script>
</body>
</html>

Then you could configure the router with the following JavaScript:

import {createRouter} from 'vanilla-ui-router';

// Initialize the router with the dynamic DOM entry point
const router = createRouter(document.getElementById('app'));

router

	// Start route: The server side URL without a hash
	.addRoute('', () => {
		/*
			Use navigateTo(…) to make dynamic route changes, i.e. to redirect to another route
		*/
		router.navigateTo('home');
	})

	.addRoute('home', (domEntryPoint) => {
		domEntryPoint.textContent = 'I am the home route.';
	})

	.addRoute('about/:aboutId/:editable', (domEntryPoint, routeParams) => {
		console.log('I am the about route.');

		/*
			routeParams are extracted from the URL and are casted to the correct type
			(Number/Boolean/String)
		*/
		console.log(routeParams); // => { aboutId: 42, editable:false }
	})

	/*
		If routes get more complex, e.g. you need to render a template URL,
		pass a configuration object as second parameter (instead of the function)
	*/
	.addRoute('route-with-template-url', {
		templateUrl: 'path/to/template.html' // is loaded and gets rendered
	})

	.addRoute('route-with-template-string/:id', {
		templateString: '<p>Lorem ipsum dolor.</p>',
		routeHandler: (domEntryPoint, routeParams) => {
			/*
			It's called just after rendering the template, so you can add route-specific logic.
			But only if needed!
			*/
		}
	})

	/*
		You can also define a templateId, i.e. if you have a template-script inside
		your markup like:

		<script type="text/template" id="template42">
			<p>
				Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolor, tenetur?
			</p>
		</script>
	*/
	.addRoute('route-with-template-id/:id', {
		templateId: 'template42'
	})

	.addRoute('route-with-dispose', {
		routeHandler: () => {},
		dispose: () => {
			// Is called before navigating to another route to do some cleanup if needed.
		}
	})

	.addRoute('inject-custom-data', {
		routeHandler: (domEntryPoint, routeParams, {customData}) => {
			// It's passed as the last parameter of the route, for instance to pass a redux store.
		},
	}, { customData: 'moep'}) // if you need to pass custom data to your routes

	.otherwise(() => {
		// If no route configuration matches, the otherwise route is invoked.
		console.log('I am the otherwise route');
		router.navigateTo('404');
	});

License

Please be aware of the licenses of the components we use in this project. Everything else that has been developed by the contributions to this project is under MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].