hono
hono copied to clipboard
Look into adding type safe routes instead of stringly types params.
What is the feature you are proposing?
Routes could look like this:
const user = defineRoute(
{
userId: param.path.string,
},
(p) => `/users/${p.userId}`
);
const { routes } = createRouter({
home: defineRoute("/"),
post: defineRoute({ postId: param.path.string }, (p) => `/post/${p.postId}`),
about: defineRoute("/about"),
user,
userSettings: user.extend("/settings"),
userActivity: user.extend("/activity"),
});
This have two benefits, inferring data from the route means you can straight up pass it to a component directly. The other benefit is when you're creating a link and need to pass it params, you get
<a
href={routes.user({userId: "2").href}link</a>
And programatically redirecting would also be supported with types
routes.post({ postId: "abc" }).push();
Hi @seivan
Currently, Hono has the RPC feature that can enable the same purpose. So, I don't want to implement it now.