0.4.0 • Published 6 years ago

laco-inferno-router v0.4.0

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

Laco Inferno Router

npm version

laco-inferno-router is a replacement for Redux First Router which makes routing a part of the state.

Routing now works with time travel and you can dispatch routing related actions that get logged in the debugger.

Example

import { render } from 'inferno'
import { Store } from 'laco'
import { Subscribe } from 'laco-inferno'
import { Route, RouterStore, Switch, Link } from 'laco-inferno-router'

import Home from './pages/Home'
import Test from './pages/Test'
import NoMatch from './pages/NoMatch'

const Counter = () => (
  <Subscribe to={[RouterStore]}>
    {state => (
      <Switch location={state.pathname}>
        <Route exact path="/" component={Home} />
        <Route exact path="/test" component={Test} />
        <Route component={NoMatch} />
      </Switch>
    )}
  </Subscribe>
)

render(<Counter />, document.getElementById('root'))

Check out the examples folder.

API

Refer to React Router documentation for following components:

  • Route
  • Switch
  • Link

RouterStore

This is the main store for routing.

// Getting the state of the store
RouterStore.get()
// Outputs something like:
// {
//   hash: "",
//   pathname: "/",
//   search: ""
// }

Actions

You may want to have more control of the routing history. You can do that by dispatching following actions:

  • push(path: string)
  • replace(path: string)
  • go(n: number)
  • goBack()
  • goForward()
import { push } from 'laco-inferno-router'

push('/test')

Actions gets automatically logged in the debugger.

For more information check out the history API here.

Credits

Heavily inspired by:

0.4.0

6 years ago

0.4.0-0

6 years ago

0.3.0

6 years ago

0.2.6-2

6 years ago

0.2.6-1

6 years ago

0.2.6-0

6 years ago

0.2.5

6 years ago

0.2.4

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago