question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NuxtLink active-classes are not applied on parents of non-nested pages

See original GitHub issue

Environment


  • Operating System: Linux
  • Node Version: v16.14.2
  • Nuxt Version: 3.0.0-rc.3
  • Package Manager: npm@7.17.0
  • Builder: vite
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/github-27bwem-nojgd6?file=pages/blog/index.vue

Describe the bug

Had a small back and forth with duboiss @ https://github.com/nuxt/framework/discussions/2086#discussioncomment-2793732

The active-classes are not always applied.

if your pages folder structure is /blog/index.vue && /blog/[slug].vue the active class is broken because ‘index’ is not the ‘slugs’ parent (i think)

if your structure is blog.vue(with NuxtPage) && blog/index.vue && blog/[slug].vue the active classes works

And im not sure if this is intended behavior or not. @duboiss said this used to work in v2 and that triggered me to create this bug-report just in case.

The folder structure is well /blog/index.vue & /blog/[slug].vue. On Nuxt 2 it was /blog/index.vue & /blog/_slug.vue.

current “workaround” is an adding a parent page with

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

which seems a bit much

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:4
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
danielroecommented, Jun 15, 2022
1reaction
vanlingcommented, May 24, 2022

Also tried a third way @duboiss no <nuxt-page/> or extra page required.

/pages/blog.vue
/pages/blog/[slug].vue
{
    name: "blog-3",
    path: "/blog-3",
    file: "/home/projects/github-27bwem-nojgd6/pages/blog-3.vue",
    children: [
      {
        name: "blog-3-slug",
        path: ":slug",
        file: "/home/projects/github-27bwem-nojgd6/pages/blog-3/[slug].vue",
        children: [],
      }
    ],
  },

@danielroe if above would be the intended way of doing a page structure like this, this “bug” changes into an DX improvement. So we could group pages into the folder and have the same behavior.

Example:

pages/blog.vue
pages/blog/[slug].vue

and

pages/blog/index.vue
pages/blog/[slug].vue

Would result in the same routing structure.

Read more comments on GitHub >

github_iconTop Results From Across the Web

router-link-active Nuxt 3 / VueJS on nested routes not applying ...
I tried that and just doesn't work - the child is never rendered (unless I add another <NuxtPage> to parent.vue which is not...
Read more >
Active Link Classes - Nuxt
Change the default NuxtLink classes and style the active and exact active classes as well as disable prefetch for a specific link.
Read more >
Troubleshooting nested pages in Nuxt.js - LogRocket Blog
Before we can create a nested page, we first have to create a root-level page, which is the parent page that will contain...
Read more >
Styling your active classes in Nuxt.js - Debbie O'Brien
By default this class is called `nuxt-link-active`. ... this will also add styles to other links such as the parent routes or the...
Read more >
How to use nuxt-link-active and nuxt-link-exact-active classes ...
Problem Apply custom active class to active route in nuxt-link tag ... will get applied to / route as well which in practice...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found