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

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

Closed
3 of 4 tasks
cyh2020 opened this issue May 17, 2024 · 4 comments
Closed
3 of 4 tasks

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

cyh2020 opened this issue May 17, 2024 · 4 comments

Comments

@cyh2020
Copy link

cyh2020 commented May 17, 2024

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

  • Would you be willing to help implement this feature?
  • Could this feature be implemented as a module?

Final checks

@cyh2020
Copy link
Author

cyh2020 commented May 17, 2024

thank you very much!!!

@cyh2020
Copy link
Author

cyh2020 commented May 28, 2024

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};
});
});
});
},
});

@cyh2020 cyh2020 closed this as completed May 28, 2024
@BobbieGoede
Copy link
Collaborator

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
Copy link
Author

cyh2020 commented May 28, 2024 via email

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

No branches or pull requests

2 participants