Skip to content

Elysia routing not working as expected for HTML5 pushState web apps #757

Answered by crishoj
sekoyo asked this question in Q&A
Discussion options

You must be logged in to vote

As far as I am aware, Elysia does not yet have an idiomatic way to specify a "default" or "catch-all" route.

You could abuse the error handler a bit to achieve the same effect though:

new Elysia()
  .use(staticPlugin({
    assets: 'public',
    prefix: ''
  }))
  .get('/api', () => 'pong')
  .onError(({code}) => {
    if (code === 'NOT_FOUND') return Bun.file('public/index.html')
  })
  .listen(3000)

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by sekoyo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants