Replies: 3 comments 8 replies
-
Hi! Use |
Beta Was this translation helpful? Give feedback.
-
I'm summoning the Asking because I got this exact question here today: https://stackoverflow.com/q/73069572/8816585 Nvm, <nuxt-link :to="{ hash: '#after' }" :external="true">After Effects</nuxt-link> Thanks Lucie! 🙏🏻 |
Beta Was this translation helpful? Give feedback.
-
This is possible by creating I suppose this to mean either Nuxt or Vue Router already converts any Live example: Stackblitz // app/router.options.ts
import type { RouterConfig } from '@nuxt/schema';
// https://router.vuejs.org/api/#routeroptions
export default <RouterConfig>{
scrollBehavior: (to, from, savedPosition) => {
// scroll to hash, useful for using to="#some-id" in NuxtLink
// ex: <NuxtLink to="#top"> To Top </NuxtLink>
if (to.hash) {
console.log('to.hash: ', to.hash);
return {
el: to.hash,
behavior: 'smooth',
};
}
// The remainder is not relevant to this discussion but maybe useful as well
// if link is to same page, scroll to top with smooth behavior
if (to === from) {
return {
left: 0,
top: 0,
behavior: 'smooth',
};
}
// this is an example for how to use saved scroll position on browser forward/back navigation
return new Promise((resolve) => {
setTimeout(() => {
resolve({
left: savedPosition?.left || 0,
top: savedPosition?.top || 0,
});
}, 500);
});
},
}; |
Beta Was this translation helpful? Give feedback.
-
Hello Experts, I'm new to web development.
I have hard time figuring out below task using nuxt-link.
<a href="#after">After Effects</a>
Nuxt link doesn't scroll like simple html code does.
<nuxt-link to="#after">After Effects</nuxt-link>
Any possible help/tip will be highly appreciated.
Beta Was this translation helpful? Give feedback.
All reactions