Skip to content
This repository has been archived by the owner on May 30, 2020. It is now read-only.

Commit

Permalink
Merge 1cbfcb7 into 00f97a8
Browse files Browse the repository at this point in the history
  • Loading branch information
sundowndev committed May 15, 2019
2 parents 00f97a8 + 1cbfcb7 commit 61fd2f3
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 13 deletions.
41 changes: 34 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,26 @@
<img src="https://i.imgur.com/DKcKGvP.png" alt="">
</p>

## 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
Expand Down Expand Up @@ -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 **<head>** or at the end of the **<body>**

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
6 changes: 4 additions & 2 deletions src/leafeon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, []);
}
}

/**
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions test/router.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {});
Expand All @@ -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 -------------------------------- //
Expand Down

0 comments on commit 61fd2f3

Please sign in to comment.