Git Product home page Git Product logo

routejs's Introduction

RouteJs

Current Version: 1.0

A simple Javascript routing library .

You just have to have basic understanding of JavaScript that's it.

Free for personal/commercial use (MIT licence).

How to install

CDN

<script src="https://cdn.jsdelivr.net/gh/joydeep11/routeJs/main/js/route-1.0.js"></script>

or you can find the main js file inside main/js folder.(Always choose the latest version)

What's inside?

A single class containing a router, and some other functions enough to build a SPA website.

Documentation

.htaccess

RewriteEngine On
# Don't rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# Rewrite everything else to index.html 
RewriteRule ^ index.html [L]

Place this in your.htaccess and keep index.html and .htaccess in the same directory. Now in your index.html file:

Declare

const router=new route();

Initialization

//Default for all links 
router.init();
//or
//for specific  links only
router.init({
link: 'a[rel="spa"]'
});
//or
//disable SPA on DOMContentLoaded for server side rendering and seo purposes
router.init({
link: 'a[rel="spa"]',
onDOMLoaded:false
});

Get url

router.get("/home",function(){
	//do staffs
});

Dynamic url

router.get("/post/{id}/{slug}",function(param){
	var id=param.id;
	var slug=param.slug;
	console.log(param)
});

Get querystring

//for /search?q=something&catagory=something

router.get("/search",function(){
if(router.getQueryParams()){
	const param=router.getQueryParams();
	var q=param.q;
	var catagory=param.catagory;
	console.log(param)
}
});

View

router.view(html,parameters={});

Example

function welcome(){
	return(`<h1>Hello {{username}}</h1>`);
}
var wlc=router.view(welcome(),{
	username: "Joydeep"
});

will return :

<h1>Hello Joydeep</h1>

Bind events on dynamically generated html

router.live(selector, evt, callback);

Example

router.live(".btn","click",function(){
	alert("clicked");
});

routejs's People

Contributors

joydeep-bhowmik avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.