nuxt-modules / i18n

I18n module for Nuxt
https://i18n.nuxtjs.org
MIT License
1.76k stars 485 forks source link

how can i add prefix before i18n language prefix? #2948

Closed cyh2020 closed 6 months ago

cyh2020 commented 6 months ago

Describe the feature

Environment

My nuxt and i18n version are: "@nuxtjs/i18n": "^8.3.1", "nuxt": "^3.11.2"

Describe the feature

folderStructure

├── pages │           └── wap |                       └──page.ts

nuxt config

i18n: { baseUrl: 'https://my-nuxt-app.com', vueI18n: "./i18n.config.ts", locales: [ { code: "english", name: "english", }, { code: "japanese", name: "japanese", ] }

what's i want?

by default ,the route to this page is —— {lang}/wap/page, but i want it be —— wap/{lang}/page

Additional information

Final checks

cyh2020 commented 6 months ago

thank you very much!!!

cyh2020 commented 6 months ago

add a module and resolved import { defineNuxtModule, extendPages, } from "nuxt/kit";

export interface ModuleOptions {}

export default defineNuxtModule({ meta: { name: "add-wap", configKey: "addWap", }, defaults: {}, async setup(_options, _nuxt) { _nuxt.hook("modules:done", () => { extendPages((pages) => { pages.forEach((page) => { const { path } = page; // Add wap path to page page.path = /wap${path}; }); }); }); }, });

BobbieGoede commented 6 months ago

Glad to hear you found a solution to your issue!

I wonder if setting the baseURL for the whole project would have worked as well https://nuxt.com/docs/api/nuxt-config#baseurl? 🤔

cyh2020 commented 6 months ago

yeah,thx,i didn't find baseurl can solve  it 

---Original--- From: "Bobbie @.> Date: Tue, May 28, 2024 18:57 PM To: @.>; Cc: @.>;"State @.>; Subject: Re: [nuxt-modules/i18n] how can i add prefix before i18n languageprefix? (Issue #2948)

Glad to hear you found a solution to your issue!

I wonder if setting the baseURL for the whole project would have worked as well https://nuxt.com/docs/api/nuxt-config#baseurl? 🤔

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you modified the open/close state.Message ID: @.***>