Support page title change.

pull/3445/head
ruibaby 2019-05-23 22:42:37 +08:00
parent ecf582bf77
commit 1552fbd950
2 changed files with 21 additions and 0 deletions

View File

@ -1,6 +1,7 @@
import Vue from 'vue'
import router from './router'
import store from './store'
import { setDocumentTitle, domTitle } from '@/utils/domUtil'
import NProgress from 'nprogress' // progress bar
import 'nprogress/nprogress.css' // progress bar style
@ -11,6 +12,7 @@ const whiteList = ['Login', 'Install', 'NotFound'] // no redirect whitelist
router.beforeEach((to, from, next) => {
NProgress.start()
to.meta && (typeof to.meta.title !== 'undefined' && setDocumentTitle(`${to.meta.title} - ${domTitle}`))
Vue.$log.debug('Token', store.getters.token)
if (store.getters.token) {
if (to.name === 'Login') {

19
src/utils/domUtil.js Normal file
View File

@ -0,0 +1,19 @@
export const setDocumentTitle = function(title) {
document.title = title
const ua = navigator.userAgent
// eslint-disable-next-line
const regex = /\bMicroMessenger\/([\d\.]+)/
if (regex.test(ua) && /ip(hone|od|ad)/i.test(ua)) {
const i = document.createElement('iframe')
i.src = '/favicon.ico'
i.style.display = 'none'
i.onload = function() {
setTimeout(function() {
i.remove()
}, 9)
}
document.body.appendChild(i)
}
}
export const domTitle = 'Halo Dashboard'