diff --git a/README.md b/README.md index 3e8c8f7..43110ea 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,26 @@

+## Table of Content + +- [Features](#features) +- [Overview](#overview) +- [Usage](#usage) + - [npm](#npm) + - [Browser](#browser) +- [Browser support](#browser-support) +- [API](#api) + - [`.add(name: string, path: string, callback: function)`](#addname-string-path-string-callback-function) + - [`.map(prefixName: string, prefixPath: string, routes: Array)`](#mapprefixname-string-prefixpath-string-routes-array) + - [`.fetchRoute(name: string[, parameters: object])`](#fetchroutename-string-parameters-object) + - [`.route: object`](#route-object) + - [`.setErrorCallback(callback: function)`](#seterrorcallbackcallback-function) + - [`.notFoundException()`](#notfoundexception) + - [`.before(path: string, callback: function)`](#beforepath-string-callback-function) + - [`.run([callback: function])`](#runcallback-function) +- [License](#license) + + ## Features - Dynamic routing & URL generator @@ -80,23 +100,30 @@ leafeon.map('docs_', '/docs', [ ]); ~~~ -## Installation (npm) +## Usage + +#### npm + +Install the package : ~~~shell -npm install leafeon +npm i leafeon --save ~~~ -#### Usage - ```js const leafeon = require('leafeon').Router(); +// or using ES6 +// import * as leafeon from 'leafeon'; +// const router = leafeon.Router(); -leafeon.add('home', '/', function () { +leafeon.add('home', '/', () => { document.write('hello world'); -}).run(); +}) + +leafeon.run(); ``` -## Browser usage +### Browser 1. Include leafeon.js in **** or at the end of the **** diff --git a/package.json b/package.json index 2bb85d9..85c8901 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "leafeon", - "version": "2.1.18", + "version": "2.1.20", "description": "Client-sided and dependency-free Javascript routing library", "author": "Sundowndev", "main": "lib/leafeon", diff --git a/src/leafeon.ts b/src/leafeon.ts index 9f393b2..4320472 100644 --- a/src/leafeon.ts +++ b/src/leafeon.ts @@ -128,7 +128,9 @@ export class Router extends RouterRequest { * @function notFoundException */ public notFoundException = (): void => { - this.notFoundCallback.apply(null, []); + if (this.notFoundCallback !== null) { + this.notFoundCallback.apply(null, []); + } } /** @@ -205,7 +207,7 @@ export class Router extends RouterRequest { }); if (targetRoute === undefined) { - return this.exception('Route ' + route + ' does not exist.'); + return this.notFoundException(); } if (!targetRoute.paramsEnabled) { diff --git a/test/router.spec.ts b/test/router.spec.ts index a89f25a..d5d3777 100644 --- a/test/router.spec.ts +++ b/test/router.spec.ts @@ -24,7 +24,7 @@ describe('Router.add', () => { // -------------------------------- FETCHROUTE FUNCTION -------------------------------- // describe('Router.fetchRoute', () => { - it('should throw exception', () => { + it('should find matching route', () => { r.routes = []; // Reset registered routes r.add('testFetchRoute', '/test-fetch-route', () => {}); @@ -34,11 +34,11 @@ describe('Router.fetchRoute', () => { assert.equal(r.getURI(), '/test-fetch-route'); }); - it('should throw exception', () => { + /*it('should call not found callback', () => { r.routes = []; // Reset registered routes assert.throws(() => { r.fetchRoute('test'); }, Error, 'Route test does not exist.'); - }); + });*/ }); // -------------------------------- FORMATPATH FUNCTION -------------------------------- //