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

[Feature]: Types Routes #6218

Open
GiancarlosIO opened this issue Sep 13, 2024 · 3 comments
Open

[Feature]: Types Routes #6218

GiancarlosIO opened this issue Sep 13, 2024 · 3 comments

Comments

@GiancarlosIO
Copy link

What problem does this feature solve?

Hi there!

Inspired by tanstack router, I have developed a simple script that analyzes the src/routes/ folder and then generates typescript code. Then it is used in our custom <Link /> component to have autocomplete in the paths and params props.

I'm just wondering if there is a plan to develop something like this. If not, maybe I can try to contribute to have this in modernjs?

Thanks!!!

What does the proposed API look like?

Simple path without params

image

Path with required params

For this you must use an object { path, params, searchParams }
image

The params property is only required by typescript if the path is a dynamic path. It also autocomplete the required params.
image

@caohuilin
Copy link
Member

PR welcome

@GiancarlosIO
Copy link
Author

Hi @caohuilin

I have created the initial version of a rspack plugin (using unplugin) with the base features (code generation). But I don't know how to integrate it with modernjs. Could you please help me with the following questions? 🙏🏼

  • Where do I put this plugin? I have reviewed the repository and found the package plugin-swc inside the cli folder. Should I add a new package there? or maybe should I create a new folder packages/plugins/route-type-generator? 🤔
  • Once I have finished with the plugin, how can I integrate it in modernjs web framework? Where is the rsbuild/rspack config that I can add the plugin? 🤔

I would also like to create a few end-to-end tests to make sure the plugin is generating the types correctly

Thanks!!!

@caohuilin
Copy link
Member

You can directly write to https://github.com/web-infra-dev/modern.js/tree/main/packages/runtime/plugin-runtime/src/router/cli. It needs to support both rspack and webpack. See if you can implement it as a plugin for rsbuild. Then add the plugin into the config function of the router plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants