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

feat(reroute): Allow for dynamic asynchronously rerouting #13176

Open
nikosgram opened this issue Dec 16, 2024 · 1 comment · May be fixed by #13186
Open

feat(reroute): Allow for dynamic asynchronously rerouting #13176

nikosgram opened this issue Dec 16, 2024 · 1 comment · May be fixed by #13186
Labels
feature / enhancement New feature or request

Comments

@nikosgram
Copy link

Describe the problem

The current SvelteKit Reroute functionality doesn't support dynamic rerouting for localization where settings are stored in a database. We need to implement a multi-domain, multi-prefix localization system that allows flexible domain/language combinations.

Example configuration:

  • Domains: example.com, example.uk, example.gr, example.fr
  • Localizations: en-gb, el-gr, en-gr, fr-fr, en-fr

Domain/prefix mappings:

el-gr:
- example.com/el-gr/
- example.gr/

en-gr:
- example.com/en-gr/
- example.gr/en/

en-gb:
- example.com/
- example.uk/

Describe the proposed solution

Modify the Reroute function to return MaybePromise<void | string> and update its implementation in server/response.js and client/client.js.

A proof-of-concept implementation: nikosgram@70d808e

I would appreciate feedback on this approach to ensure I'm not overlooking any potential issues or better alternatives.

Alternatives considered

No response

Importance

i cannot use SvelteKit without it

Additional Information

No response

@nikosgram
Copy link
Author

nikosgram commented Dec 16, 2024

An example of how this could work:

import type { Reroute } from '@sveltejs/kit';

export const reroute: Reroute = async ({ url }) => {
    if (url.pathname.startsWith('/api')) {
        return;
    }
    
    const response = await fetch(url.protocol + '//' + url.host + '/api/locales');

    const locales = await response.json(); // as Type[];

    // write re-routing logic here
};

@eltigerchino eltigerchino added the feature / enhancement New feature or request label Dec 17, 2024
@nikosgram nikosgram linked a pull request Dec 17, 2024 that will close this issue
6 tasks
@eltigerchino eltigerchino linked a pull request Dec 18, 2024 that will close this issue
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature / enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants