简体   繁体   English

如何使用nuxt-link和i8n导航子页面?

[英]How to navigate subpages with nuxt-link and i8n?

I can obviously call simple pages like so: <nuxt-link :to="localePath('about')"> = http://127.0.0.1:3000/about-us 我显然可以像这样调用简单的页面: <nuxt-link :to="localePath('about')"> = http://127.0.0.1:3000/about-us

But calling <nuxt-link :to="localePath('addItem/food')"> return me to root. 但是调用<nuxt-link :to="localePath('addItem/food')">将我带回root。 So does <nuxt-link :to="localePath('food')"> when I'm on the addItem page. 当我在addItem页面上时, <nuxt-link :to="localePath('food')">也是如此。 ( http://127.0.0.1:3000/ ) http://127.0.0.1:3000/

If I simply put <nuxt-link :to="localePath('addItem')"> I'm taken to addItem/index, but it's the only thing that work. 如果我只是简单地输入<nuxt-link :to="localePath('addItem')">我就会被添加到addItem / index中,但这是唯一有效的方法。

How can I properly navigate to addItem/food? 如何正确导航到addItem / food?

Pages: 页数:

pages: {
        'addItem/index': {
          en: '/add-item',
          fr: '/ajout-item',
        },
        'addItem/food': {
          en: '/add-item/food',
          fr: '/ajout-item/alimentation',
        },
        'addItem/pharma': {
          en: '/add-item/pharmaceuticals',
          fr: '/ajout-item/medicaments',
        },
        about: {
          en: '/about-us', // -> accessible at /about-us (no prefix since it's the default locale)
          fr: '/a-propos', // -> accessible at /fr/a-propos
        }
      },

If I input the url directly it works. 如果我直接输入网址,则可以。

How can I get nuxt-link/localePath to properly print the link? 如何获得nuxt-link / localePath来正确打印链接?

I had the same issue. 我遇到过同样的问题。 After some research and a deeper look in the generated router.js inside the ".nuxt" Folder, you can see the generated routes in the function "createRouter()". 经过研究并更深入地了解了“ .nuxt”文件夹中生成的router.js,您可以在函数“ createRouter()”中看到生成的路由。 There you can see, that the name of each route contains the path. 在那里,您可以看到每个路由的名称都包含路径。 But in this case the path is simply linked by a hyphen. 但是在这种情况下,路径仅通过连字符链接。

For your example this should work as follows: <nuxt-link :to="localePath('addItem-food')"> 对于您的示例,它应如下所示: <nuxt-link :to="localePath('addItem-food')">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM