storeon-isorouter
v0.0.3
Published
Isomorphic storeon module for url routing on client and server
Readme
Storeon Isomorphic Router
Storeon Router which solves the problem of routing your application on server and browser.
Installation
npm install storeon-isorouter
# or
yarn add storeon-isorouterUsage
Import the isorouter.createRouter from storeon-isorouter and add this module to createStore.
import createStore from 'storeon'
import isorouter from 'storeon-isorouter'
const store = createStore([
isorouter.createRouter()
])
const Root = () => {
const { [isorouter.key]: route } = useStoreon(isorouter.key)
switch (route.path) {
case "/":
return <Main/>
case "/blog/":
return <Blog/>
default:
return <NotFound/>
}
}
store.dispatch(isorouter.navigate, '/')Define your own link component and subsribe route changing on click events.
import isorouter from 'storeon-isorouter'
const Link = ({href, children}) => {
const { dispatch } = useStoreon(isorouter.key)
const handleClick = (e) => {
e.preventDefault()
dispatch(isorouter.navigate, href)
}
return <a href={href} onClick={handleClick}>{children}</a>
}API
import isorouter from 'storeon-isorouter'
const moduleRouter = isorouter.createRouter()isorouter.key – key for store.
isorouter.navigate – navigation action.
LICENSE
MIT
