Nuxt3 子路由和导航中的活动类

huangapple go评论64阅读模式
英文:

Nuxt3 Child routes and active class in navigation

问题

I have a navigation - One of the link is linking to "/users" (Nuxt3 project)

当我在"/users"路线上时,我有一个子导航链接到"/users/groups"

但是当我登陆到"/users/groups"路线时,即使"/users/groups"是子路线,主导航上也没有活动类?

我的结构如下:

Nuxt3 子路由和导航中的活动类

/users/index.vue和/users/groups/index.vue布局都使用了<NuxtPage :page-key="$route.path" />

我需要以不同的方式构建它,以使我的主导航看到"/users/groups"是"/users"的子路线,然后添加活动类吗?

英文:

I have a navigation - One of the link is linking to "/users" (Nuxt3 project)

When I'm on the "/users" route, I have a subnavigation linking to "/users/groups"

But when I land on the route "/users/groups" - I don't get the active class in the main navigation on the "/users", even though "/users/groups" is a child route?

My structure looks like this:

Nuxt3 子路由和导航中的活动类

The layout both /users/index.vue and /users/groups/index.vue uses outputs &lt;NuxtPage :page-key=&quot;$route.path&quot; /&gt;

Do I need to structure it differently to get my main navigation to see that "/users/groups" are a child of "/users" and then add the active class?

答案1

得分: 2

Your structure is correct. You just need to create a users.vue file inside the pages with the NuxtPage content.

~/pages/users.vue

<template>
    <div>
        <NuxtPage />
    </div>
</template>

I created an example for you and it is working. See screenshot:
Nuxt3 子路由和导航中的活动类

Hope that helps you.

英文:

Your structure is correct. You just need to create a users.vue file inside the pages with the NuxtPage content.

~/pages/users.vue

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

&lt;template&gt;
    &lt;div&gt;
        &lt;NuxtPage /&gt;
    &lt;/div&gt;
&lt;/template&gt;

<!-- end snippet -->

I created an example for you and it is working. See screenshot
https://stackblitz.com/edit/nuxt-starter-w48c5q?file=pages/users/index.vue
Nuxt3 子路由和导航中的活动类

Hope that helps you

huangapple
  • 本文由 发表于 2023年5月10日 19:05:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/76217654.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定