UNPKG

domdope

Version:

A dope JavaScript library for creating user interfaces.

31 lines (25 loc) 667 B
class Router { constructor(render) { this._render = render window.onpopstate = render } get pathname() { return window.location.pathname } goTo(pathname) { window.history.pushState({}, pathname, window.location.origin + pathname) this._render() } redirectTo(pathname) { window.history.replaceState({}, pathname, window.location.origin + pathname) this._render() } } const withRouter = Component => { return (dope, props) => { const router = new Router(dope._render) // Mix in router with other props under a logical namespace. return Component(dope, { ...props, router }) } } export default withRouter