Router usage
See original GitHub issueHi guys! I’m loving this framework, many compliments!
Unfortunately at the moment I’m experiencing a strange problem, I cannot make the router work. This is my code:
'use strict'
const choo = require('choo')
const html = require('choo/html')
const view1 = (state, prev, send) => {
return html`<h1>Hello!</h1>`
}
const view2 = (state, prev, send) => {
return html`<h1>World!</h1>`
}
const app = choo()
app.router([
['/', view1],
['/world', view2]
])
const tree = app.start()
document.body.appendChild(tree)
If I go into the brawser at the url
everything is ok, If I go to url/world
I get a 404. Even if I set a default route (I tried both budo and bankai to compile the code).
Probably I’m lost in a glass of water, can you help me?
Thanks!
Issue Analytics
- State:
- Created 7 years ago
- Comments:5
Top Results From Across the Web
How to Use a Router - The Home Depot
1. What does a router do? It allows you to make:; Customized cuts to shape the edges of a board 2. You can...
Read more >What is a Router? - Definition and Uses - Cisco
A router receives and sends data on computer networks. Routers are sometimes confused with network hubs, modems, or network switches. However, routers can ......
Read more >6 Beginner Ways to Use a Woodworking Router - Bob Vila
Routers can be used to cut patterns, grooves, and designs across multiple pieces of wood. For instance, if you have a broken table...
Read more >What Is a Router and How to Use One: The Beginner's FAQ
Routers are the nodes that make up a computer network like the internet. The router you use at home is the central node...
Read more >How to Check Data Usage on a Wi-Fi Router - Lifewire
How Do I Check My Wi-Fi Usage? ... Most home routers have some form of built-in data tracking. You can access that via...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@delvedor - this isn’t a choo specific issue, but an issue for single page apps in general. http://jaketrent.com/post/pushstate-webpack-dev-server/ there’s a good article explaining how to use webpack dev server.
Personally I’ve found
budo --pushstate
more than adequate during dev, and a simple express server catching all routes to serve index.html for production.Using budo, I was able to get it to work by passing in the option
--pushstate
. This causes budo to always serve index.html (and not 404). I don’t know if there’s a way for choo to expose the routes to budo, but what I’ve done in the past is have my build scripts build an index.html at each route (e.g./index.html
,/hello/index.html
,/world/index.html
)I’ve run into this issue in React as well, not sure if this is the best solution, but meh, it works.