-
Notifications
You must be signed in to change notification settings - Fork 14
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 request] Domain-based routing #99
Comments
Hi, at the moment this library provides only two helper methods, useful for the localization of the path:
Implementing domain management is not difficult: just create a helper method that returns the domain based on the language. And resolve the locale in the In any case, we could add the support in the library:
I have two doubts:
Then in dev mode I think it should use prefixing. Opinions? |
Thanks for taking the time to answer me,
Agree here, the library gives you everything you need to solve this.
Other thing that comes to my mind is that if you declare routes without prefix, devs will need to handle redirects if language doesn't match. For example: // default domain: dutch.nl
// supported domains: spanish.es | english.com
[
{ paths: { 'huis-ibiza': 'casa-ibiza' } }, // spanish
{ paths: { 'huis-ibiza': 'villa-ibiza' } }, // english
] If a user goes to dutch.nl/villa-ibiza it will probably work, right? I guess you can add some logic to plugin/middleware and use |
Yes, it should work, but we would lose the mapping with the language to know which URLs are valid (I'll have to do some testing, maybe we could handle it by using an optional So, let's imagine the expected behavior for both methods ( - Dev mode (prefix = true)
- Prod mode (optional prefix = true)
- Prod mode (optional prefix = false)
If a lang have no domain, we could use default domain with prefix:
I was thinking of a configuration like this:
What do you think? |
Yes, this was what I was trying to say haha. - Dev mode (prefix = true) - Prod mode (optional prefix = true) Why? You can solve this in many different ways:
- Prod mode (optional prefix = false)
The config file looks perfect and really close to what you have today. |
Hi @fprl, the feature is available in the latest release: https://github.com/robisim74/qwik-speak/releases/tag/v0.18.0 Let me know. |
Hi @robisim74 , thanks a lot for pushing this feature. I'm trying to add it to my project but I get an error:
I follow the Domain-based routing section in the docs, and there is a thing that I don't know if its a typo or you forgot to implement it; In the import { qwikSpeakInline, toPrefixAsNeeded } from 'qwik-speak/inline';
import { rewriteRoutes } from './src/speak-routes';
export default defineConfig(({ mode }) => {
return {
plugins: [
qwikCity({ rewriteRoutes: toPrefixAsNeeded(rewriteRoutes, mode) }),
/* */
],
};
}); Do you think this is related? Contextspeak-config.tsexport const config: SpeakConfig = {
rewriteRoutes: toPrefixAsNeeded(rewriteRoutes),
defaultLocale: { lang: "nl", currency: "EUR", timeZone: "Europe/Amsterdam" },
supportedLocales: [
{ lang: "nl", currency: "EUR", timeZone: "Europe/Amsterdam" },
{ lang: "en", currency: "GBP", timeZone: "Europe/London" },
{ lang: "de", currency: "EUR", timeZone: "Europe/Berlin" },
{ lang: "fr", currency: "EUR", timeZone: "Europe/Paris" },
{ lang: 'it', currency: 'EUR', timeZone: 'Europe/Rome' },
// { lang: 'en-US', currency: 'USD', timeZone: 'America/Los_Angeles' }
],
domainBasedRouting: { prefix: 'as-needed' },
} speak-routes.tsimport type { RewriteRouteOption } from 'qwik-speak';
import { domains } from './speak-config';
// Translation paths
export const rewriteRoutes: RewriteRouteOption[] = [
{ domain: domains.nl, paths: { 'huis-ibiza': 'huis-ibiza' } },
{ domain: domains.en, paths: { 'huis-ibiza': 'villa-ibiza' } },
{ domain: domains.de, paths: { 'huis-ibiza': 'villa-ibiza' } },
{ domain: domains.fr, paths: { 'huis-ibiza': 'villa-ibiza' } },
{ domain: domains.it, paths: { 'huis-ibiza': 'villa-ibiza' } },
] plugin.tsPlugin.ts is a copy of the docs file. |
As in the code you posted, in It has a different import, because in the Vite configuration file it is executed during compilation. |
Then in the |
Good catch. Though I just updated everything and have the same issue:
vite.config.tsimport { defineConfig } from "vite";
import { qwikVite } from "@builder.io/qwik/optimizer";
import { qwikCity } from "@builder.io/qwik-city/vite";
import { qwikSpeakInline, toPrefixAsNeeded } from 'qwik-speak/inline';
import tsconfigPaths from "vite-tsconfig-paths";
import { rewriteRoutes } from "./src/i18n/speak-routes";
export default defineConfig(({ mode }) => {
return {
plugins: [
qwikCity({ rewriteRoutes: toPrefixAsNeeded(rewriteRoutes, mode), trailingSlash: false }),
qwikVite(),
qwikSpeakInline({
defaultLang: 'nl',
supportedLangs: ['nl', 'en', 'de', 'fr', 'it'],
assetsPath: './src/i18n'
}),
tsconfigPaths(),
],
}); speak-config.tsimport { type SpeakConfig, toPrefixAsNeeded } from 'qwik-speak';
import { rewriteRoutes } from './speak-routes';
export const config: SpeakConfig = {
rewriteRoutes: toPrefixAsNeeded(rewriteRoutes),
defaultLocale: { lang: "nl", currency: "EUR", timeZone: "Europe/Amsterdam" },
supportedLocales: [
{ lang: "nl", currency: "EUR", timeZone: "Europe/Amsterdam" },
{ lang: "en", currency: "GBP", timeZone: "Europe/London" },
{ lang: "de", currency: "EUR", timeZone: "Europe/Berlin" },
{ lang: "fr", currency: "EUR", timeZone: "Europe/Paris" },
{ lang: 'it', currency: 'EUR', timeZone: 'Europe/Rome' },
// { lang: 'en-US', currency: 'USD', timeZone: 'America/Los_Angeles' }
],
domainBasedRouting: { prefix: 'as-needed' },
}; speak-routes.tsimport type { RewriteRouteOption } from 'qwik-speak';
import { domains } from './speak-config';
// Translation paths
export const rewriteRoutes: RewriteRouteOption[] = [
{ domain: domains.nl, paths: {} },
{ domain: domains.en, prefix: 'en', paths: { 'huis-ibiza': 'villa-ibiza' } },
{ domain: domains.de, prefix: 'de', paths: { 'huis-ibiza': 'villa-ibiza' } },
{ domain: domains.fr, prefix: 'fr', paths: { 'huis-ibiza': 'villa-ibiza' } },
{ domain: domains.it, prefix: 'it', paths: { 'huis-ibiza': 'villa-ibiza' } },
] plugin.tsPlugin.ts is a copy of the docs file. |
Ok, now the config if correct. Uhm... the function is this: https://github.com/robisim74/qwik-speak/blob/main/packages/qwik-speak/tools/core/routing.ts
|
|
The circular dependency was the issue, thank you so much. Its amazing how you thought about all the routing cases. |
Question, do you think its possible to have the same name for a route in different languages? I can see the issue here but I don't know if it can be solved due to how qwik handles routes.
|
The problem is related to Qwik City and to the fact that the routing is file-based: therefore it finds multiple paths pointing to the same file. Unfortunately it's a behavior I can't fix from this library. |
Yes, I was sure it was that, Astro works the same way. Thank you again for pushing this :) |
One question about how Because that way I could easily manage this, for example:
Does this makes sense? |
qwik-speak/packages/qwik-speak/src/routing.ts Line 249 in 8d48ac3
EDIT: Works as expected, I should handle redirects manually in this case but its easy as only one path is localized. |
Hi Roberto, I'm wondering if the last version of qwik/qwik-city with this commit fix this issue? QwikDev/qwik#6375 Regards |
Hi there,
Thank you for your work, this library is amazing.
I was wondering if Domain-based routing is something you are interested in support.
Example.
Thank you.
The text was updated successfully, but these errors were encountered: