All Projects → totaljs → jRouting

totaljs / jRouting

Licence: MIT License
Great routing mechanism for client-side web applications

Programming Languages

javascript
184084 projects - #8 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to jRouting

Browser
Create Elm programs that run in browsers!
Stars: ✭ 284 (+1675%)
Mutual labels:  spa, history
Frontexpress
An Express.js-Style router for the front-end
Stars: ✭ 263 (+1543.75%)
Mutual labels:  spa, history
dowels
🔨 a tiny but powerful javascript library that performs client-side routing, templating, and REST API communication to help you get your single-page web applications running in seconds
Stars: ✭ 13 (-18.75%)
Mutual labels:  spa
edliz
This 7th essential medicines list and standard treatment guidelines for the most common health conditions in Zimbabwe has been endorsed by the National Medicine & Therapeutics Policy Advisory Committee [NMTPAC]. It is the product of many years of combined efforts by hundreds of health workers at all levels of the health care system in Zimbabwe. …
Stars: ✭ 25 (+56.25%)
Mutual labels:  spa
xRoute
一个小型的前端路由库✈️
Stars: ✭ 36 (+125%)
Mutual labels:  spa
iwata-asks-downloader
Tool to download Iwata Asks interviews (none of which are stored in this repo)
Stars: ✭ 17 (+6.25%)
Mutual labels:  history
wechat-spa
🎉 微信端单页面应用(SPA)常见问题汇总及解决方案
Stars: ✭ 337 (+2006.25%)
Mutual labels:  spa
imgalign
Webapplication for image stitching and aligning
Stars: ✭ 162 (+912.5%)
Mutual labels:  spa
ItroublveTSC
Official Source of ItroublveTSC, totally open source. No virus or anything. Feel free to have a look :)
Stars: ✭ 82 (+412.5%)
Mutual labels:  history
brn
The idea of this project is to design and make a web-application (with scientist cooperation) which would contained series of special audio trainings to support people with central auditory skills deficit to allow them to train them to listen better.
Stars: ✭ 41 (+156.25%)
Mutual labels:  spa
ChRIS ui
UI for ChRIS
Stars: ✭ 20 (+25%)
Mutual labels:  spa
mo360-ftk
MO360 Frontend Toolkit: A toolkit for single page applications (SPA) based on React and Typescript that allows to extract single features into microfrontends.
Stars: ✭ 54 (+237.5%)
Mutual labels:  spa
super-simple-dockerized-spa
Illustrating how to wrap a single page application in docker.
Stars: ✭ 25 (+56.25%)
Mutual labels:  spa
hstdb
Better history management for zsh. Based on ideas from https://github.com/larkery/zsh-histdb.
Stars: ✭ 25 (+56.25%)
Mutual labels:  history
stimulus todomvc
[WIP] An implementation of TodoMVC using Ruby on Rails and StimulusJS
Stars: ✭ 14 (-12.5%)
Mutual labels:  spa
meet-the-fans
Query and Visualize the network graph of your GitHub repositories, followers, stargazers, and forks.
Stars: ✭ 22 (+37.5%)
Mutual labels:  history
RSSR
React Server Side Rendering boilerplate with Authentication structure
Stars: ✭ 41 (+156.25%)
Mutual labels:  spa
webviewhs
🌐 A Haskell binding to the webview library created by Serge Zaitsev.
Stars: ✭ 109 (+581.25%)
Mutual labels:  spa
wordpress
Free PWA & SPA for Wordpress & Woocommerce
Stars: ✭ 103 (+543.75%)
Mutual labels:  spa
natural js
Natural-JS : Javascript Front-End Architecture Framework
Stars: ✭ 35 (+118.75%)
Mutual labels:  spa

MIT License

Support

jRouting

The library supports the HTML 5 History API only. This plugin is a little big cannon for the web development. Works only with jQuery.

YOU MUST SEE:

Simple example

// ===========================
// DEFINE ROUTING
// ===========================

// jRouting === global variable
jRouting.route('/homepage/', view_homepage, init_homepage);
jRouting.route('/products/{category}/', view_products, ['data']);

// ROLES + OPTIONS
// v4.0 for jComponent and v3.0 classic version
jRouting.route('/secure/area/', view_products, ['auth', '@rolename1', '@rolename2', { custom: 'options' }]);

jRouting.middleware('auth', function(next, options, roles) {
    console.log(options);
    // --> { custom: 'options' }
    console.log(roles);
    // --> ['rolename1', 'rolename2']
});


// Supports HASHTAG routes
jRouting.route('#users', view_homepage, init_homepage);
jRouting.route('#products', view_homepage, init_homepage);
// jRouting.redirect('#users');

// ===========================
// DEFINE MIDDLEWARE
// ===========================

jRouting.middleware('data', function(next) {
    next();
    // next(new Error('Some error'))
    // IMPORTANT: jRouting won't execute any next middleware and a target route
});

// ===========================
// DEFINE VIEWS
// ===========================

function view_homepage() {
    var self = this;
    // self === jRouting
    $('#content').html('HOMEPAGE');
}

function init_homepage(next) {
    // is executed one time
    next();
}

function view_products(category) {
    // self === jRouting
	$('#content').html('PRODUCTS –> ' + category);
}

// ===========================
// DEFINE EVENTS
// ===========================

jRouting.on('location', function(url) {
     var menu = $('.menu');
     menu.find('.selected').removeClass('selected');
     menu.find('a[href="' + url + '"]').parent().addClass('selected');
});

Properties

jRouting.url;

{String} - Current URL address.

console.log(jRouting.url);

jRouting.version;

{Number} - Current framework version.

console.log(jRouting.version);

jRouting.history;

{String Array} - History list (LIMIT_HISTORY === 100).

console.log(jRouting.history);

jRouting.errors;

{String Array} - Error list (LIMIT_HISTORY_ERROR === 100).

console.log(jRouting.errors);

jRouting.global;

{Empty object} - Temporary global object for storing a temporary data.

jRouting.global.secret = 'AbcaDUIAZ349';
jRouting.global.name = 'total.js';

jRouting.repository;

{Empty Object} - A temporary object for the current location. This property remembers last state for the URL.

jRouting.repository.title = 'jRouting';

jRouting.model;

{Object} - model for the current location.

jRouting.redirect('/new-url/', { name: 'jRouting '});

// --> view

function view_new_url() {
	var self = this;
	console.log(self.model); // --> model.name: jRouting
}

jRouting.query;

{Object} - Get the current params from the URL address (url -> query). After redirect or refresh are params re-loaded.

// ---> /current-page/?q=jComponent
console.log(jRouting.query.q);

Methods

jRouting.route(path, fn, [middleware], [init])

Create a route.

jRouting.route('/', view_homepage);
jRouting.route('/products/{category}/', view_products, ['middleware']);
jRouting.route('/products/{category}/', view_products, ['middleware'], function(next) {
    // initialization function
    next();
});

// OR
ROUTE('/', view_homepage);

jRouting.middleware(name, fn)

Create a middleware

jRouting.middleware('latest', function(next, options, roles) {
    // continue
	next();
});

jRouting.redirect(url, [model])

Redirect.

jRouting.redirect('/products/shoes/');

// or

jRouting.redirect('/products/shoes/', { from: 'jeans', latest: true, custom: 'model' });

jRouting.prev()

Returns the previouse URL address.

console.log(jRouting.prev());

jRouting.back()

Goes back to previous URL.

jRouting.back();

jRouting.refresh()

Refresh the current page.

jRouting.refresh();

Events

jRouting.on('ready')

Is the library ready?

jRouting.once('ready', function() {
	console.log('I\'m ready');
	jRouting.redirect('/homepage/');
});

jRouting.on('location')

Captures a new location.

jRouting.on('location', function(url) {
	console.log('new location --->', url);
});

jRouting.on('error')

Captures some error.

jRouting.on('error', function(error, url, description) {
	console.log('ERROR --->', error, url, description);
});

jRouting.on('status')

Captures a HTTP error.

jRouting.on('status', function(code, message) {
	switch (code) {
		case 404:
			console.log('NOT FOUND', message);
			break;
		case 500:
			console.log('INTERNAL ERROR', message);
			break;
	}
});

Assign links to jRouting

IMPORTANT: doesn't work with hashtags. Hashtags doesn't need a prevention for redirecting.

jR.clientside('a.jrouting');

// or
// <div class="jrouting" data-jr="/homepage/">CLICK ON ME</div>
jR.clientside('div.jrouting');

Alias: jRouting is too long as word

// use alias:
// jR === jRouting
jR.route('/', ...);

+v1.3.0 Async loading

<script async src="jquery.min.js"></script>
<script async src="jrouting.min.js"></script>
if (!window.jRoute)
    window.jRoute = [];

window.jRoute.push(function() {
    jRouting.route('/', function() {
        console.log('Classic route');
    });

    jRouting.route('#hashtag', function() {
        console.log('Hashtag');
    });
});

Contact

Peter Širka - www.petersirka.eu / [email protected]

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].