Giter VIP home page Giter VIP logo

es6-router's Introduction

ES6 Router

A simple client side router built in ES6.

Usage

const router = new Router({ ... })
  .add(() => {
    // getPage('/');
  })
  .add(/about/, () => {
    // getPage('about');
  })
  .add('contact', () => {
    // getPage('contact');
  });

router.remove('contact');
router.navigate('about');

API

constuctor

Param Type Description
options Object Options object
options.debug boolean (false) Enable debugging
options.context Object (window) Context to add event listener to
options.startListening boolean (true) Start listening when router is created

currentRoute ⇒ string

Name of the current route

Returns: string - Current route


add(route, handler) ⇒ Router

Add a new route

Param Type Description
re string | RegExp Name of route to match
handler function Method to execute when route matches

Returns: Router - This router instance


remove(route, [handler]) ⇒ Router

Remove a route from the routerc

Param Type Description
re string | RegExp Name of route to remove
[handler] function Function handler to remove

Returns: Router - This router instance


reload() ⇒ Router

Reload the current route

Returns: Router - This router instance


check() ⇒ Router

Recheck the path and reload the page

Returns: Router - This router instance


listen([instance]) ⇒ Router

Start listening for hash changes on the window

Param Type Default Description
[instance] any Window Context to start listening on

Returns: Router - This router instance


stopListen([instance]) ⇒ Router

Stop listening for hash changes on the window

Param Type Default Description
[instance] any Window Context to stop listening on

Returns: Router - This router instance


navigate(path) ⇒ Router

Navigate router to path

Param Type Description
path string Path to navigate the router to

Returns: Router - This router instance


navigateError(hash) ⇒ Router

Navigate to the error page

Param Type
hash string

Returns: Router - This router instance


cleanPath(path) ⇒ string

Strip the path of slashes and hashes

Param Type Description
path string Path to clean of hashes

Returns: string - Cleaned path

License

MIT

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.