From b66e5909be88d8df88c9830e09e9c6e19700c2ba Mon Sep 17 00:00:00 2001 From: sundowndev Date: Fri, 21 Sep 2018 17:21:41 +0200 Subject: [PATCH 01/15] Documentation --- README.md | 86 +++++++++++++++++++++++++++---------------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/README.md b/README.md index 34a0064..1c75861 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,19 @@ # router.js

- Version - Size - Size minified + Version + Size + Size minified

-Simple client sided router. You don't need node, you can use it in static html pages for documentation, personal website etc. +Simple client sided router for static websites such as documentation, personal website etc. ## Features -- Static & dynamic route patterns +- Static & dynamic routing - Custom 404 error handling - Before and after router middleware -- Prefixing route paths +- Prefixed route paths ## Overview @@ -63,48 +63,37 @@ Mapping routes using a route prefix ~~~js // This will create two routes under /#/docs prefix -router.map('page_', '/docs', [ +router.map('docs_', '/docs', [ { - name: 'index', + name: 'intro', route: '/', callback: function () { content.innerHTML = '' + - '

index page

' + '

Introduction

' ; } }, { - name: 'tutorial', - route: '/tutorial', + name: 'get_started', + route: '/get-started', callback: function () { content.innerHTML = '' + - '

This is a tutorial!

' + '

Get started

' ; } } ]); ~~~ -### Using npm - -```js -var Router = require('@sundowndev/router.js'); - -var router = Router(); - -router.add('home', '/', function () { - console.log('hello world'); -}); - -router.run(); -``` - ### API Fetch a route by name or path ~~~ js router.fetchRoute('home'); // or router.fetchRoute('/'); + +// with parameters +router.fetchRoute('hello', {name: 'Sundown'}); ~~~ Get the current route @@ -113,15 +102,15 @@ Get the current route router.route ~~~ -This will ouput : +This will return : ~~~ { - name: "home", - route: "/", + name: [string], + route: [string], callback: [function], - paramsEnabled: false, - params: [] + paramsEnabled: [boolean], + params: [array] } ~~~ @@ -152,17 +141,29 @@ router.add('projects', '/projects/:title', function (sProjectTitle) { $ npm i @sundowndev/router.js ~~~ +#### Usage + +```js +var Router = require('@sundowndev/router.js'); + +var router = Router(); + +router.add('home', '/', function () { + document.write('hello world'); +}); + +router.run(); +``` + + ## Installation -1. Include router.js at the end of the body +1. Include router.js in **** or at the end of the **** ~~~html -~~~ - -or via jsdelivr's CDN -~~~html + ~~~ @@ -175,18 +176,17 @@ or via jsdelivr's CDN ~~~ -3. Create some routes and run the router +3. Create some routes ~~~js router.add('home', '/', function () { - content.innerHTML = '' + - '
' + - '

Welcome!

' + - '

wow, such routing

' + - '
' - ; + document.write('Hello!'); }); +~~~ +4. Run the router + +~~~js router.run(); ~~~ From 480dce9fd893bb2be98f804896cbc4e4001d35fe Mon Sep 17 00:00:00 2001 From: sundowndev Date: Fri, 21 Sep 2018 17:21:59 +0200 Subject: [PATCH 02/15] Demo with fetchRoute() --- demo/index.html | 3 +-- demo/routes.js | 10 +++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/demo/index.html b/demo/index.html index fe0ad45..75c7a39 100644 --- a/demo/index.html +++ b/demo/index.html @@ -45,10 +45,9 @@

Router.js

- - +