mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-16 19:04:48 +00:00
19 lines
500 B
TypeScript
19 lines
500 B
TypeScript
import destr from 'destr'
|
|
import { defineNuxtPlugin, useNuxtApp } from '../nuxt'
|
|
|
|
export default defineNuxtPlugin({
|
|
name: 'nuxt:restore-state',
|
|
hooks: {
|
|
'app:mounted' () {
|
|
const nuxtApp = useNuxtApp()
|
|
try {
|
|
const state = sessionStorage.getItem('nuxt:reload:state')
|
|
if (state) {
|
|
sessionStorage.removeItem('nuxt:reload:state')
|
|
Object.assign(nuxtApp.payload.state, destr<Record<string, any>>(state)?.state)
|
|
}
|
|
} catch {}
|
|
}
|
|
}
|
|
})
|