How to use catch all routes with Kemal

For a Vue.js single page application – at least on a SUB URL of our page – we want a catch all on our server, which will always render the same template / HTML output to the browser.

Kemal is internally based on Radix for routing:

Radix has a Catch All / Glob character: *

Therefore, if we want to create a catch all route, we simply write:

get “/debug/*” do |env|
   render “src/views/hello.ecr”   
end

This will match, for example:

  • /debug
  • /debug/
  • /debug/anything
  • /debug/anything/as/deep/as/you/want

This will NOT match:

  • /debug3

Further reading / Code: