|
import { h, app } from "hyperapp" |
|
import { Link, Route, Switch, Redirect, location } from "@hyperapp/router" |
|
|
|
const state = { |
|
location: location.state, |
|
counter: 0 |
|
} |
|
|
|
const actions = { |
|
location: location.actions, |
|
up: (value)=>(state)=>{counter: state.counter + value}, |
|
down: (value)=>(state)=>{counter: state.counter - value} |
|
} |
|
|
|
|
|
const Home = ({location,match})=>{ |
|
return ( |
|
<div> |
|
<h1>Home!</h1> |
|
<hr /> |
|
</div> |
|
) |
|
} |
|
|
|
const Hello = ({location,match})=>{ |
|
return ( |
|
<div> |
|
<h1>Hello!</h1> |
|
<hr /> |
|
</div> |
|
) |
|
} |
|
|
|
const MyComponent = (state, actions) => ({location,match})=>{ |
|
// console.log(state); |
|
console.log(actions); |
|
return ( |
|
<div> |
|
<h1>Counter Component</h1> |
|
<h3>{state.counter}</h3> |
|
<button onclick={() => actions.up(1)} >+</button> |
|
<button onclick={() => actions.down(1)} >-</button> |
|
<hr /> |
|
</div> |
|
) |
|
}; |
|
|
|
const Info = state => ({location,match})=>{ |
|
// console.log("from Info()"); |
|
// console.log(location); |
|
console.log(match); |
|
return (<div> |
|
<h1>Page Info </h1> |
|
<br /> |
|
<h3>LOCATION:</h3> |
|
<h3>Url: {location.pathname}</h3> |
|
<h3>prior: {location.previous}</h3> |
|
<br /> |
|
<h3>MATCH:</h3> |
|
<h3>exact?: {match.isExact.toString()}</h3> |
|
<h3>params: {match.params}</h3> |
|
<h3>path: {match.path}</h3> |
|
<h3>url: {match.url}</h3> |
|
</div> |
|
) |
|
} |
|
|
|
|
|
const Navigation = () => { |
|
return ( |
|
<nav> |
|
<ul> |
|
<li><Link to="/">Home</Link></li> |
|
<li><Link to="/hello">Hello</Link></li> |
|
<li><Link to="/counter">Counter</Link></li> |
|
<li><Link to="/old">Redirect to Counter</Link></li> |
|
<li><Link to="/noRoute">No Route</Link></li> |
|
</ul> |
|
<hr/> |
|
</nav> |
|
) |
|
} |
|
|
|
|
|
const view = (state, actions)=>{ |
|
return ( |
|
<div> |
|
<Navigation /> |
|
<Switch> |
|
<Route path="/" render={Home} /> |
|
<Route path="/hello" render= {Hello} /> |
|
<Route path="/counter" render= {MyComponent(state, actions)} /> |
|
<Route path="/old" render={() => <Redirect from="/old" to="/counter" />} /> |
|
<Route render={Info(state, actions)} /> |
|
</Switch> |
|
</div> |
|
) |
|
} |
|
|
|
const main = app(state, actions, view, document.body) |
|
|
|
const unsubscribe = location.subscribe(main.location) |
UPDATE: as I have actually gone through the process to Run this on my local - many of the issues are resolved...
🤦♂️
So the only applicable questions are:
Any help is greatly appreciated.