iamntz
iamntz
NNuxt
Created by iamntz on 8/23/2024 in #❓・help
Translate custom routes with i18n?
it's much more hacky than i would like, but hey, at least it does the job, so... yay?
5 replies
NNuxt
Created by iamntz on 8/23/2024 in #❓・help
Translate custom routes with i18n?
i managed to make it work by ditching custom-routes module and using app/router.options.ts instead, like so:
import type { RouterConfig } from "nuxt/schema";

import routes_i18n from "../config/routes";

const customRoutes = {
miau: {
route: routes_i18n.miau,
component: () => import("~/pages/custom-component-page.vue"),
},
};

export default {
routes: (_routes) => {
const routes = [..._routes]; // <<< because _routes is readonly

Object.entries(customRoutes).forEach(
([routeName, { route, component }]) => {
Object.entries(route).forEach(([lang, path]) => {
routes.push({
path: `/${lang}${path}`,
name: `${routeName}___${lang}`,
component,
});
});
}
);
return routes;
}
} satisfies RouterConfig;
import type { RouterConfig } from "nuxt/schema";

import routes_i18n from "../config/routes";

const customRoutes = {
miau: {
route: routes_i18n.miau,
component: () => import("~/pages/custom-component-page.vue"),
},
};

export default {
routes: (_routes) => {
const routes = [..._routes]; // <<< because _routes is readonly

Object.entries(customRoutes).forEach(
([routeName, { route, component }]) => {
Object.entries(route).forEach(([lang, path]) => {
routes.push({
path: `/${lang}${path}`,
name: `${routeName}___${lang}`,
component,
});
});
}
);
return routes;
}
} satisfies RouterConfig;
5 replies
NNuxt
Created by iamntz on 8/23/2024 in #❓・help
Translate custom routes with i18n?
My setup is the following:
//nuxt.config.ts
export default defineNuxtConfig({
modules: [
CustomRoutesModule,
'@nuxtjs/i18n',
],
i18n: {
// lazy: true,
defaultLocale: 'en',
strategy: 'prefix',
customRoutes: 'config',
pages: {
about: {// <<<<<< this works
en: "/about-us",
it: "/chi-siamo",
},
miau: {//<<<< this doesn't
en: "/miau-translated",
it: "/miau-translated-in-it",
},
},
})
//nuxt.config.ts
export default defineNuxtConfig({
modules: [
CustomRoutesModule,
'@nuxtjs/i18n',
],
i18n: {
// lazy: true,
defaultLocale: 'en',
strategy: 'prefix',
customRoutes: 'config',
pages: {
about: {// <<<<<< this works
en: "/about-us",
it: "/chi-siamo",
},
miau: {//<<<< this doesn't
en: "/miau-translated",
it: "/miau-translated-in-it",
},
},
})
// custom-routes.ts
import { defineNuxtModule, createResolver } from "@nuxt/kit";

export default defineNuxtModule({
setup(options, nuxt) {
const { resolve } = createResolver(import.meta.url);

nuxt.hook("pages:extend", (pages) => {
pages.push({
name: "miau",
path: "/miau",
file: resolve("../app/pages/custom-component-page.vue"),
});
});
},
});
// custom-routes.ts
import { defineNuxtModule, createResolver } from "@nuxt/kit";

export default defineNuxtModule({
setup(options, nuxt) {
const { resolve } = createResolver(import.meta.url);

nuxt.hook("pages:extend", (pages) => {
pages.push({
name: "miau",
path: "/miau",
file: resolve("../app/pages/custom-component-page.vue"),
});
});
},
});
5 replies
NNuxt
Created by iamntz on 8/16/2024 in #❓・help
How would you build a ... search page?
for example, one the fact that i have to serialize the query on both client (for router updates) and on server action (to send to api) feels ... odd
4 replies
NNuxt
Created by iamntz on 8/16/2024 in #❓・help
How would you build a ... search page?
can't really pin-point, it's just a gut feeling 😄 (i'm new to nuxt)
4 replies