1.0.2 • Published 5 years ago

domr-router v1.0.2

Weekly downloads
1
License
ISC
Repository
github
Last release
5 years ago

DOMR Router

A static router for creating hash routes.

Install

Use npm or yarn to install domr-router

    npm install domr-router --save
    
    yarn add domr-router

Use Router

    import { Router } from 'domr-router';
    import HomePageView from './views/HomePageView';
    import ConfigView from './views/ConfigView';

    const router = new Router([
      {
        path: '/',
        view: HomePageView,
        isDefault: true,
      },
      {
        path: '/config/',
        view: ConfigView,
      },
      {
        path: '/config/:topic',
        view: ConfigView,
      },
    ]);

    router.Start();
    
    

Router supports wildcard entries like (*, :name)

Router class

Router() class takes array of routes as the first parameter. The routes object contains two main parameter and one optional isDefault parameter.

  • path - hash url location
  • view - a function to execute (without parentheses)
  • isDefault (optional) - if set true then the route becomes the default path

.Start()

Initializes the router

Advanced Router class props

    ...

    const router = new Router(routes, {
      refreshPage: true,
    });

    ...
    
    

Besides the first parameter i.e. the array of routes Router class also takes config obj as the second parameter.

  • refreshPage - if set true then refresh the page on every hash change
1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago