Skip to content

fluxury/pure-flux-router

Repository files navigation

pure-flux-router

CircleCI

Overview

A router for single page applications:

  1. Wraps DOM APIs for window and history.
  2. Routes defined with paths, similar to express.
  3. Content loaded async. Works with code splitting.

Usage

Router Setup

var {promiseAction} = require('pure-flux')
var {loadContent, loadRoutes} = require('pure-flux-router')

let routes = [{
    path: '/',
    load: () => System.import('./pages/home').then( cmp => loanContent(cmp) )
  } {
    path: '*',
    load: () => System.import('./pages/error_not_found').then( cmp => loanContent(cmp) )
  }]

loadRoutes( routes )

Open path programmically

import {location} from 'pure-flux-router'
location.open('/buckets/1')

Use redirect to change the URL without adding an entry to the history state.

location.redirect('/buckets')

Replace routes

Change the routes.

loadRoutes([{
  path: '/',
  load: loadContent( System.import('./pages/home') )
}])

Final thoughts

Experimental. Untested in wide variety of browsers.