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.

configurable `scrollBehavior`

See original GitHub issue

Environment


  • Operating System: Darwin
  • Node Version: v16.11.0
  • Nuxt Version: 3.0.0-27267528.292b524
  • Package Manager: npm@8.0.0
  • Bundler: Vite
  • User Config: buildModules, css, meta
  • Runtime Modules: -
  • Build Modules: nuxt-windicss@^2.0.3

Describe the bug

scrollBehavior setting (which is available in Nuxt2) doesn’t work. I tried both nuxt.config.ts router.scrollBehavior and putting router.scrollBehavior.js in project route but they have no effect.

I couldn’t find any document on scrollBehavior at Nuxt3 docs website… Is there any way to make it work?

Reproduction

nuxt.config.ts

import { defineNuxtConfig } from 'nuxt3'

export default defineNuxtConfig({
  // ......
  router: {
    scrollBehavior: () => ({ x: 0, y: 0 }),
  },
})

~/router.scrollBehavior.js

export default () => {
  console.log('here') // never called
  return { x: 0, y: 0 }
}

Additional context

No response

Logs

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:35 (5 by maintainers)

github_iconTop GitHub Comments

16reactions
dergunovscommented, Nov 30, 2021

You can set this in a plugin:

export default defineNuxtPlugin((nuxtApp) => {
  nuxtApp.$router.options.scrollBehavior = () => {
    return { left: 0, top: 0 }
  }
})

This fix works not so smooth. White blink spoils the impression.

11reactions
danielroecommented, Nov 5, 2021

You can set this in a plugin:

export default defineNuxtPlugin((nuxtApp) => {
  nuxtApp.$router.options.scrollBehavior = () => {
    return { left: 0, top: 0 }
  }
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

Scroll Behavior | Vue Router
The scrollBehavior function receives the to and from route objects, like Navigation Guards. The third argument, savedPosition , is only available if this...
Read more >
ScrollBehavior class - widgets library - Flutter - Dart API docs
Describes how Scrollable widgets should behave. Used by ScrollConfiguration to configure the Scrollable widgets in a subtree. This class can be extended to ......
Read more >
scroll-behavior - CSS: Cascading Style Sheets - MDN Web Docs
The scroll-behavior CSS property sets the behavior for a scrolling box when scrolling is triggered by the navigation or CSSOM scrolling APIs ...
Read more >
Scroll Behavior Configuration | LivePerson Developer Center
lp_scroll_when_push_notification configures the scroll behavior when open conversation screen by tapping on push notification. LivePerson.
Read more >
Add configurable scroll behavior to the Menu component
If another default number of results shown initially is set, we will need to configure this limit to be 10 for TypeaheadSearch. In...
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