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 with anchor-link (#id) does not work.

See original GitHub issue

Environment

Nuxt CLI v3.0.0-rc.3 23:26:06 RootDir: C:\Users\sebas\JavascriptProjects\sebbejohansson-front 23:26:08 Nuxt project info: 23:26:08


  • Operating System: Windows_NT
  • Node Version: v17.8.0
  • Nuxt Version: 3.0.0-rc.3
  • Package Manager: yarn@1.22.10
  • Builder: vite
  • User Config: telemetry, ssr, target, generate, router, app, css, modules, storyblok, build, env
  • Runtime Modules: -
  • Build Modules: -

👉 Report an issue: https://github.com/nuxt/framework/issues/new 23:26:08

👉 Suggest an improvement: https://github.com/nuxt/framework/discussions/new

👉 Read documentation: https://v3.nuxtjs.org

Reproduction

In the header of my portfolio page there are NuxtLinks that has this kind of link. Nuxt3 Branch: https://github.com/SebbeJohansson/sebbejohansson-front/tree/56adf54503aa0fbd1ea308e721184fb9ae3fc30a

Describe the bug

Linking to any anchor link with a # to go to a specific id in the DOM does not work. No scroll is triggered.

Additional context

Switching to a normal works. The same <NuxtLink> tags work in Nuxt2.

Logs

No response

github_iconTop GitHub Comments

qin-guancommented, May 29, 2022

This behavior is identical to vue-router, a link to an anchor does not scroll to the element by default (see https://router.vuejs.org/guide/advanced/scroll-behavior.html).

To customize this behavior, see https://v3.nuxtjs.org/guide/directory-structure/pages/#router-options.

In app/router.options.ts, this configuration works for me:

import type { RouterConfig } from '@nuxt/schema';

// https://router.vuejs.org/api/#routeroptions
export default <RouterConfig>{
  scrollBehavior(to, from, savedPosition) {
    return { el: to.hash };
  },
};

Demo: https://stackblitz.com/edit/github-rwcdcs?file=app/router.options.ts

0reactions
iBobikcommented, Oct 23, 2022

This issue is closed, so I created feature request: #8424 Let’s upvote it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

vue.js - Anchor in Nuxt component not working on same page ...
I am using Nuxt 3 and having the same problem, I solved the problem using this with thoughts of helping Nuxt 3 devs...
Read more >
click.prevent is not working on properly on a NuxtLink - Get Help
I've been playing with Nuxt (2.15.7) and for whatever reason @click.stop does not work properly in my application. Here's a very simple ...
Read more >
Insert and manage anchor links - HubSpot Knowledge Base
Learn how to create an anchor link to help your visitors navigate to a specific section of your content without scrolling.
Read more >
<NuxtLink> · Nuxt Components
<NuxtLink> is a drop-in replacement for both Vue Router's <RouterLink> component and HTML's <a> tag. It intelligently determines whether the link is ......
Read more >
[Solved]-How to create a dynamic anchor link in nuxt.js?-Vue.js
How can I spy on a function from setup in vuejs3? Vuejs Property or method “welcome” is not defined · vue2 and composition...
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