1.0.2 • Published 6 years ago

routering v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

Routering

This is a simple, zero dependancy, routing library that can be used with fastn to map the page location to a specific component.

Getting started

Clone this repo and run the example:

git clone git@github.com:markwylde/router.git
cd router
npm install
npm run start

Then goto: http://localhost:8080

Usage

Install the library

npm i --save routering

Activate the router

const routeModule = require('routering')
routeModule({
  defaultRoute: '/'
}, route => {
  // This will be called anytime the route changes
  fastn.Model.set(state, 'route', route)
})

Define your route templater

const ui = fastn('templater', {
  data: fastn.binding('route'),
  attachTemplates: false,
  template: function (data) {
    const route = data.get('item')

    switch (route) {
      case '/':
        return homePage()

      case '/second':
        return secondPage()

      case '/third':
        return thirdPage()
  
      default:
        return notFoundPage()
    }
  }
})

License

This project is licensed under the terms of the MIT license.

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago