我使用nuxtjs 2.10.x和i18n模块。 Nu自定义中间件或类似的东西。路由工作正常。
我的nuxt.config.js
模块/ 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对所有页面都给出了类似的警告。而且没有任何线索为什么会这样。可能是什么问题?
答案 0 :(得分:2)
用于为当前语言环境生成url的localePath()
函数抛出此错误。
奇怪的是,它无法通过处理传入的url来工作,而是通过尝试匹配vue路由器中定义的路由的name属性来实现:
要找到页面的网址,我们需要按以下方式编写网址:
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"
答案 1 :(得分:0)
<nuxt-link :to="localePath({ name: 'your-dynamic-path' })">
Some text...
</nuxt-link>
我就是这样配置的。