Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple page Nav - how to use with <a href="/#foo"> #32 #364

Open
atiar-cse opened this issue Sep 10, 2020 · 1 comment
Open

Multiple page Nav - how to use with <a href="/#foo"> #32 #364

atiar-cse opened this issue Sep 10, 2020 · 1 comment

Comments

@atiar-cse
Copy link

The codes are working but the problem is, when I have the href like <a href="/#anchor">Anchor</a>, it does not seem to work with my codes. If I have the same without the forward slash, it works like <a href="#anchor">Anchor</a>.
When visit new route (/contact-us) - it loaded as base_url/contact-us#anchor and never works because the #anchor section inside home page.

I am using vue-router.

Any help will be appreciated.

@smuriu
Copy link

smuriu commented Mar 31, 2022

Hi, just came across this issue. I faced a similar challenge in a nuxt 3 app. My solution was to add an event listener that would look at the route hash parameter, then programatically scrollTo the target (see below)

// ~/plugins/vue-scrollto.ts

import VueScrollTo from 'vue-scrollto'

export default defineNuxtPlugin(({ vueApp, hook }) => {
  vueApp.use(VueScrollTo)

  hook('page:finish', () => {
    const { hash } = useRoute()
    if (hash) {
      VueScrollTo.scrollTo(hash)
    }
  })
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants