Typescript: Scroll Behaviour type support in 'app/router.scrollBehavior.ts'

Created on 21 Sep 2020  路  4Comments  路  Source: nuxt/typescript

right now doing this

`import { Route } from "vue-router";

const scrollBehavior = (to: Route, from: Route, savedPosition: any) => {
console.log(savedPosition);
console.log(to);
console.log(from);
return { x: 0, y: 0 };
};
export default scrollBehavior;`

has no affect. (console.log shows nothing) whereas changing it to .js works fine.
im trying to push to a page (kept alive) with the last saved position.

feature request

Most helpful comment

@e-lobo Yeah so I was right, there's no currently workaround for now, I'm myself using a .js version in my Nuxt TypeScript projects. I will reach Nuxt Core Team to see if we can enable TypeScript support for this file for Nuxt 3.

All 4 comments

@e-lobo Unfortunately there is no support for TypeScript for this feature, you may want to try with nuxt-ts, but I think it's overall tied to Nuxt internals which looks for a .js file.

@kevinmarrec yes i am using it with nuxt-ts.. works with .js only

@e-lobo Yeah so I was right, there's no currently workaround for now, I'm myself using a .js version in my Nuxt TypeScript projects. I will reach Nuxt Core Team to see if we can enable TypeScript support for this file for Nuxt 3.

I have this in one of my projects. It is a vue-cli project so not sure if you can use it for nuxt but here you go...

import { RouterScrollBehavior } from 'vue-router';

const scrollBehavior: RouterScrollBehavior = (to, from, savedPosition) => {
  // Different return options here
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

JakubKoralewski picture JakubKoralewski  路  6Comments

dclovec picture dclovec  路  4Comments

negezor picture negezor  路  6Comments

stevenho0811 picture stevenho0811  路  3Comments

b-m-f picture b-m-f  路  6Comments