-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathgatsby-browser.js
More file actions
33 lines (27 loc) · 791 Bytes
/
Copy pathgatsby-browser.js
File metadata and controls
33 lines (27 loc) · 791 Bytes
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
const NProgress = require('nprogress')
const { fromPathTo } = require('./helpers')
exports.onPreRouteUpdate = ({ location }) => {
navigator.serviceWorker.getRegistrations().then(function(registrations) {
for (let registration of registrations) {
if (!!registration) {
console.log('unregistering service worker, bye bye...')
registration.unregister()
}
}
})
const pathname = window.location.pathname
const paths = fromPathTo()
if (paths[pathname]) {
console.log('reidrecting to...', paths[pathname])
window.location.replace(paths[pathname])
} else {
window.location.replace(paths['/'])
}
NProgress.start()
}
exports.onRouteUpdateDelayed = () => {
NProgress.start()
}
exports.onRouteUpdate = () => {
NProgress.done()
}