Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Look into adding type safe routes instead of stringly types params. #2561

Open
seivan opened this issue Apr 25, 2024 · 1 comment
Open

Look into adding type safe routes instead of stringly types params. #2561

seivan opened this issue Apr 25, 2024 · 1 comment
Labels
enhancement New feature or request.

Comments

@seivan
Copy link

seivan commented Apr 25, 2024

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();
@seivan seivan added the enhancement New feature or request. label Apr 25, 2024
@yusukebe
Copy link
Member

Hi @seivan

Currently, Hono has the RPC feature that can enable the same purpose. So, I don't want to implement it now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request.
Projects
None yet
Development

No branches or pull requests

2 participants