kit icon indicating copy to clipboard operation
kit copied to clipboard

[V3] should have a way to programmatically define routes

Open ptrxyz opened this issue 6 months ago • 4 comments

Describe the problem

Currently there is no way to modularize SvelteKit apps mostly due to there not being a way for a component to export its own routes.

I understand that this is a big endeavor and I figured that modularized SvelteKit is not a priority for the Svelte team currently and for the foreseeable future (milestone 3 doesn't seem to contain any issues related to this at least).

For my team and me this means we have to find another way of doing this and I wonder if there is a way to programmatically define routes that are outside of the routes folder.

Describe the proposed solution

I would like to see an API giving more access to the Sveltekit router to be able to define routes programmatically since it's not possible to define them outside the routes folder (i.e. in packages).

Alternatives considered

We try to work around this with exporting handle functions but then the package can't define the path structure inside the package.

We then tried +server.ts and exporting routes as API routes. This leads to lost type safety and many other Sveltekit features simply not working (form actions, SSR, etc)

Obviously the best would be to be able for a package to ship its own routes but whole this is not possible, I wonder if it's possible to expose the Sveltekit router in a more flexible way so that routes can be defined in a different way than just through the file system. And while we are on it -- something to query the router i.e. list all known routes would be nice. But that's a different story I guess.

Importance

i cannot use SvelteKit without it in larger teams for larger projects

Additional Information

No response

ptrxyz avatar May 20 '25 03:05 ptrxyz

Related: #3369

ptrxyz avatar May 20 '25 04:05 ptrxyz

Also found #8896 There, some solutions from other frameworks are proposed.

ptrxyz avatar May 20 '25 04:05 ptrxyz

And also related, a very old one: https://github.com/sveltejs/kit/issues/1251 This seems to pop up constantly over the years. 😅

ptrxyz avatar May 20 '25 04:05 ptrxyz

This is very much relevant. I think there was a discussion about externalizing the built-in router which could be a good first step.

david-plugge avatar May 24 '25 22:05 david-plugge