-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgatsby-browser.tsx
53 lines (46 loc) · 1.42 KB
/
gatsby-browser.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import * as React from 'react'
import type { GatsbyBrowser } from 'gatsby'
import { AnimatePresence } from 'framer-motion'
import 'prismjs/themes/prism.css'
import './src/assets/scss/style.scss'
export const wrapPageElement: GatsbyBrowser['wrapPageElement'] = ({ element }) => {
return
;<AnimatePresence wait>{element}</AnimatePresence>
}
export const onServiceWorkerUpdateReady = () => {
const answer = window.confirm(`This application has been updated. ` + `Reload to display the latest version?`)
if (answer === true) {
window.location.reload()
}
}
export const shouldUpdateScroll = ({ routerProps: { location, transitionDelay }, getSavedScrollPosition }) => {
if (location.action === 'PUSH') {
window.setTimeout(() => {
window.scrollTo({
top: 0,
behavior: 'smooth',
})
}, transitionDelay)
} else {
const savedPosition = getSavedScrollPosition(location) || [0, 0]
const top = savedPosition[1]
window.setTimeout(() => {
window.scrollTo({
top,
behavior: 'smooth',
})
}, transitionDelay)
}
return false
}
export const onRouteUpdate = ({ location }) => {
if (process.env.NODE_ENV !== 'production') {
return null
}
const pagePath = location ? location.pathname + location.search + location.hash : undefined
setTimeout(() => {
if (typeof gtag === 'function') {
gtag('event', 'page_view', { page_path: pagePath })
}
}, 100)
}