|
@@ -1,13 +1,34 @@
|
|
|
-import { createRouter, createWebHashHistory, Router } from 'vue-router';
|
|
|
-import routes from './routes-teacher';
|
|
|
+import { Dialog } from 'vant'
|
|
|
+import { createRouter, createWebHashHistory, Router } from 'vue-router'
|
|
|
+import routes from './routes-teacher'
|
|
|
const router: Router = createRouter({
|
|
|
history: createWebHashHistory(),
|
|
|
routes
|
|
|
-});
|
|
|
+})
|
|
|
|
|
|
router.beforeEach((to, from, next) => {
|
|
|
- document.title = (to.meta.title || '酷乐秀') as any;
|
|
|
- next();
|
|
|
-});
|
|
|
+ document.title = (to.meta.title || '酷乐秀') as any
|
|
|
+ next()
|
|
|
+})
|
|
|
|
|
|
-export default router;
|
|
|
+let isOpen = false
|
|
|
+router.onError(error => {
|
|
|
+ if (error instanceof Error) {
|
|
|
+ const isChunkLoadFailed = error.name.indexOf('chunk')
|
|
|
+ const targetPath = router.currentRoute.value.fullPath
|
|
|
+ if (isChunkLoadFailed && !isOpen) {
|
|
|
+ isOpen = true
|
|
|
+ Dialog.alert({
|
|
|
+ title: '更新提示',
|
|
|
+ message: 'APP有更新请点击确定刷新页面?',
|
|
|
+ confirmButtonColor: 'var(--van-primary)'
|
|
|
+ }).then(() => {
|
|
|
+ // on close
|
|
|
+ location.hash = targetPath
|
|
|
+ window.location.reload()
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+})
|
|
|
+
|
|
|
+export default router
|