pure-flux-router
v2.0.2
Published
A simple router for pure-flux, based on history.pushState.
Downloads
14
Maintainers
Readme
pure-flux-router
Overview
A router for single page applications:
- Wraps DOM APIs for window and history.
- Routes defined with paths, similar to express.
- 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.