mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-12 23:35:58 +00:00
32 lines
717 B
JavaScript
32 lines
717 B
JavaScript
import Vue from 'vue'
|
|
|
|
let lastRoute
|
|
const keepAliveHook = {}
|
|
|
|
if (!process.server) {
|
|
keepAliveHook.install = (Vue) => {
|
|
const keepAlivePages = process.env.keepAlivePages || []
|
|
|
|
Vue.mixin({
|
|
// Save route if this instance is a page (has metaInfo)
|
|
mounted() {
|
|
if (this.$metaInfo) {
|
|
lastRoute = this.$route.name
|
|
}
|
|
},
|
|
activated() {
|
|
if (this.$metaInfo) {
|
|
lastRoute = this.$route.name
|
|
}
|
|
},
|
|
deactivated() {
|
|
// If this is a page and we don't want it to be kept alive
|
|
if (this.$metaInfo && !keepAlivePages.includes(lastRoute)) {
|
|
this.$destroy()
|
|
}
|
|
},
|
|
})
|
|
}
|
|
Vue.use(keepAliveHook)
|
|
}
|