hyperapp-router
hyperapp-router copied to clipboard
Cannot read property 'name' of undefined
Getting error when going to /edge
import { Link, Route, Switch, location } from "@hyperapp/router";
import welcome from "./views/welcome";
import edge from "./views/edge";
const routes = (state, actions) =>
Switch({}, [
Route({ path: "/", render: welcome }),
Route({ path: "/edge", render: edge })
]);
export default routes;
If you're using a named instance, like const main = app(state, actions, view, document.body)
I was having a similar issue and had to pass in main
instead of state
:
import { h, app } from 'hyperapp'
import { Link, Route, location } from '@hyperapp/router'
import { div, p, ul, li } from '@hyperapp/html'
const Home = () => p('Hello, World!')
const Ryan = main => p(`Hello, ${state.name}!`)
const state = {
location: location.state,
name: 'Ryan'
}
const actions = {
location: location.actions,
speak: state => console.log('Hi')
}
const view = (state, actions) => div([
ul([
li([ Link({ to: '/' }, 'Home') ]),
li({ onclick: actions.speak }, [ Link({ to: '/ryan' }, 'Ryan') ])
]),
Route({ path: '/', render: Home }),
Route({ path: '/ryan', render: Ryan})
])
const main = app(state, actions, view, document.body)
const unsubscribe = location.subscribe(main.location)