-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Routes defined in code #2922
Comments
I would just like to add that this could also serve as a base for i18n of routes. We could add an |
What I would expect/require from this system:
I don't care about the syntax that much... router builder or something could be used as long as it enables route type-safety for most cases... just use whatever is available in TS and make sure the code is type-safe.
|
Realistically this isn't going to happen — it would make SvelteKit significantly less maintainable and harder to learn, even if we could come up with a good design for it (the example above would defeat code-splitting, for example) that addressed all the challenges around who 'wins' in a disagreement between the fs routes and the code routes. Filesystem-based routing is fairly universal at this point (every major metaframework uses it, even the one from the React Router team), and it would be better to spend our energy on addressing any shortcomings we find within that approach rather than adding a separate one. |
Describe the problem
Would sveltekit ever consider an option for defining the routes in code using objects? This is mainly for the sake of maintainability. Currently if I need to refactor a route I have a minimum of 2 places I need to update, the directory structure and then any enums I use for navigation.
The file based system is really nice to get going fast and there are obviously some great pros to doing it that way. I do think that having routes defined in objects or in the code in some manner also has pros to it and would be a nice additional alternative to the filed based system.
Describe the proposed solution
How this object would precisely be structured I'm not sure, but I figure it would be similar to the file structure in many ways. Possibly something similar to what React Router V6 has done?
React Router V6 example from their documentation.
An off the cough idea. I'm sure this can be updated and improved upon significantly as well.
I've found having objects works well for referencing routes in the code base and makes refactoring simple. You could always allow both objects or lists to be used to describe the routes as in my small example above.
Not sure if this becomes a bit too open, as I do understand there has to be some standard way of doing things.
Alternatives considered
No response
Importance
nice to have
Additional Information
No response
The text was updated successfully, but these errors were encountered: