NuxtJS i18n [vue-router] 名称为 about_us___en 的路由不存在
NuxtJS i18n [vue-router] Route with name about_us___en does not exist
我正在使用 nuxtjs 2.10.x 和 i18n 模块。 Nu 自定义中间件或类似的东西。路由工作正常。
我的 nuxt.config.js
modules/i18n 部分:
...
modules: [
'@nuxtjs/axios',
'@nuxtjs/pwa',
'@nuxtjs/auth',
'@nuxtjs/dotenv',
'nuxt-fontawesome',
[
'nuxt-i18n',
{
locales: [
{
code: 'en',
iso: 'en-US',
file: 'en.json',
name: 'English'
},
{
code: 'zh',
iso: 'zh-CN',
file: 'zh.json',
name: '简体中文'
}
],
lazy: true,
langDir: 'locales/',
defaultLocale: 'en',
strategy: 'prefix_except_default',
differentDomains: false,
vueI18n: {
fallbackLocale: 'en'
},
detectBrowserLanguage: {
useCookie: true,
cookieKey: 'lang'
}
}
]
],
...
页面文件夹结构:
'pages/'
|--'contact_us.vue'
|--'_lang/'
|--'contact_us.vue'
但是我收到了这个疯狂的警告:[vue-router] Route with name 'contact_us___en' does not exist
。实际上 nuxt 对我拥有的所有页面都给出了类似的警告。而且没有任何线索为什么会这样。可能有什么问题?
此错误由用于为当前语言环境生成 url 的 localePath()
函数引发。
奇怪的是,它无法通过操纵传入的 url 来工作,而是通过尝试匹配 vue router 中定义的路由名称 属性:
也就是说要找到一个页面的url我们需要这样写:
localePath('index') >>> "/"
localePath('login') >>> "/login"
localePath('tech-test') >>> "/tech/test"
以下方式会抛出错误并默认为'/'
localePath('/') >>> "/"
localePath('/login') >>> "/"
localePath('tech/test') >>> "/"
文档:https://nuxt-community.github.io/nuxt-i18n/basic-usage.html#nuxt-link
编辑:
我已经提交了一个 pullrequest,允许将路径用作字符串:
localePath('/') >>> "/"
localePath('/tech/test') >>> "/tech/test"
<nuxt-link :to="localePath({ name: 'your-dynamic-path' })">
Some text...
</nuxt-link>
这就是我的配置方式。
我正在使用 nuxtjs 2.10.x 和 i18n 模块。 Nu 自定义中间件或类似的东西。路由工作正常。
我的 nuxt.config.js
modules/i18n 部分:
...
modules: [
'@nuxtjs/axios',
'@nuxtjs/pwa',
'@nuxtjs/auth',
'@nuxtjs/dotenv',
'nuxt-fontawesome',
[
'nuxt-i18n',
{
locales: [
{
code: 'en',
iso: 'en-US',
file: 'en.json',
name: 'English'
},
{
code: 'zh',
iso: 'zh-CN',
file: 'zh.json',
name: '简体中文'
}
],
lazy: true,
langDir: 'locales/',
defaultLocale: 'en',
strategy: 'prefix_except_default',
differentDomains: false,
vueI18n: {
fallbackLocale: 'en'
},
detectBrowserLanguage: {
useCookie: true,
cookieKey: 'lang'
}
}
]
],
...
页面文件夹结构:
'pages/'
|--'contact_us.vue'
|--'_lang/'
|--'contact_us.vue'
但是我收到了这个疯狂的警告:[vue-router] Route with name 'contact_us___en' does not exist
。实际上 nuxt 对我拥有的所有页面都给出了类似的警告。而且没有任何线索为什么会这样。可能有什么问题?
此错误由用于为当前语言环境生成 url 的 localePath()
函数引发。
奇怪的是,它无法通过操纵传入的 url 来工作,而是通过尝试匹配 vue router 中定义的路由名称 属性:
也就是说要找到一个页面的url我们需要这样写:
localePath('index') >>> "/"
localePath('login') >>> "/login"
localePath('tech-test') >>> "/tech/test"
以下方式会抛出错误并默认为'/'
localePath('/') >>> "/"
localePath('/login') >>> "/"
localePath('tech/test') >>> "/"
文档:https://nuxt-community.github.io/nuxt-i18n/basic-usage.html#nuxt-link
编辑: 我已经提交了一个 pullrequest,允许将路径用作字符串:
localePath('/') >>> "/"
localePath('/tech/test') >>> "/tech/test"
<nuxt-link :to="localePath({ name: 'your-dynamic-path' })">
Some text...
</nuxt-link>
这就是我的配置方式。