app.vue判断的方法,根据 "path" 这个标识,如果本地存的标识!==pathIdentification的时候,证明不是在home页里:
export default {
data () {
return {
}
},
methods: {
_isMobile () {
const flag = navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i)
return flag
}
},
mounted () {
console.log('路由', localStorage.getItem('path'))
const path = localStorage.getItem('path')
if (path !== 'pathIdentification') {
console.log('进入了')
if (this._isMobile()) {
console.log('手机端')
this.$router.replace('/phoneLogin')
} else {
console.log('pc端')
this.$router.replace('/login')
}
}
}
}
跳转到pc首页/移动端首页的时候,本地添加一个标识,当关闭这个页面的时候,再销毁,这样就能解决刷新就跳转到首页的问题
export default {
mounted () {
console.log('移动端home路由', this.$route.path)
const id = 'pathIdentification'
localStorage.setItem('path', id)
},
destroyed () {
localStorage.removeItem('path')
}
}