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

Add parameters to loader functions #189

Open
craumix opened this issue Aug 26, 2024 · 0 comments
Open

Add parameters to loader functions #189

craumix opened this issue Aug 26, 2024 · 0 comments

Comments

@craumix
Copy link

craumix commented Aug 26, 2024

Currently the loader function can not load translations dynamically, passing the current route or even parameters would allow for better usage.

My example use case would by I have and article that is located under article/[articleId], so once the user navigates to the article the translation for that article only should be loaded. I can do this by loading the correct translation from my DB in the +page.server.ts but doing it directly trough the translation library would be cleaner.

The current loader function is export type T = () => Promise<Translations.Input>;. A simple solution would just be to pass the current route to the loader like export type T = (route: string) => Promise<Translations.Input>;.

A more advanced version would be to allow parameters in the routes for a loader, similar to how sveltekit params work.
So for example defining the routes as /article/{articleId} (or article/[articleId]) and the loader as export type T = (params: {[key: string]: string}) => Promise<Translations.Input>; it would then pass

{
  "articleId": "some_id"
}

to the loader function.

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

No branches or pull requests

1 participant