Simply you can use keep-alive in Vue js to cache states on back action. For more information: https://v2.vuejs.org/v2/api/#keep-alive
keep alive support in Vue2 and also Vue3, but the syntax is different. Also you can use in Nuxt.
For better performance you should limit components to be caches by "max" and "include" props.
you can use in layout or only wrap components:
Wrap in layout:
<keep-alive> <router-view :key="$route.fullPath"></router-view> </keep-alive>
Wrap components to cache:
<keep-alive> <product-list></product-list> </keep-alive>
Nuxt:
<template> <div> <Nuxt keep-alive :keep-alive-props="{ exclude: ['modal'],max:3 }" /> </div> </template>
** Keep alive should be in the same layout(if you use keep alive in layout).
** If you destroy keep alive cache, the caching will not work anymore.
** You can control cache with "key" props. For same "key" component will show from cache.
** Keep alive only cache states. So for keep scroll, you should store last position as state and set scroll position on activated hook.
** Lifecycle doesn't work on cache mode and you should use activated and deactivated hooks.
localStorage.