Which Hono Router Should I Use in This Case?
Hono has five different routers:
1. PatternRouter
2. SmartRouter
3. LinearRouter
4. TrieRouter
5. RegExpRouter
I need a router that matches the pathname exactly, regardless of the order in which routes are defined. Meaning if in my source code, however I order or define my API paths and endpoints.
5 Replies
trierouter will match the pathname exactly iirc
I asked Gemini, ChatGPT, Claude, and Grok. All of them chose different ones, only Grok answered by TrieRouter, which is most likely right.
Though an official confirmation from Hono team would be much helpful.
I've implemented a trie-router myself in kotlin, that's why I said it would most likely be the one you want
did you try reading the source code?
routing handling is also pretty easy to test locally
TrieRouter splits the url in segments, and makes a tree out of them
so the order of the routes does not matter