Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// imported only in development
const hotClient = require('webpack-hot-middleware/client')
hotClient.subscribe(function (event) {
if (event.action === 'reload') {
// force page reload when html-webpack-plugin template changes
window.location.reload()
}
})
var hotClient = require('webpack-hot-middleware/client')
// 订阅事件,当 event.action === 'reload' 时执行页面刷新
hotClient.subscribe(function (event) {
if (event.action === 'reload') {
window.location.reload()
}
})
export const init = ({ router }) => {
window.__SABER_DEV_CLIENT_ID__ = Math.random()
.toString(36)
.substring(7)
client.subscribe(obj => {
if (obj.action === 'router:push' && obj.id === __SABER_DEV_CLIENT_ID__) {
if (obj.hasError) {
console.error(`You need to refresh the page when the error is fixed!`)
}
if (obj.alreadyBuilt) {
router.push(obj.route)
} else {
const handler = status => {
if (status === 'idle') {
module.hot.removeStatusHandler(handler)
router.push(obj.route)
}
}
module.hot.addStatusHandler(handler)