vueルーティングリダイレクト
2839 ワード
1、main.js判断ジャンプ
2、router.jsルーティング
import Vue from 'vue'
import App from './App'
import router from './router/common'
import Dialog from 'hsy-vue-dialog'
import store from './store/'
import './config/style'
import HappyScroll from 'vue-happy-scroll'
import 'vue-happy-scroll/docs/happy-scroll.css'
import 'babel-polyfill'
import './common/js/common.js'
import ECharts from 'vue-echarts'
Vue.component('chart', ECharts)
const isDebug_mode = process.env.NODE_ENV !== 'production'
Vue.config.debug = isDebug_mode
Vue.config.devtools = isDebug_mode
Vue.config.productionTip = isDebug_mode
Vue.use(HappyScroll)
Vue.use(Dialog)
router.beforeEach((to, from, next) => {
//
if (
!sessionStorage.getItem('auid') &&
(to.path !== '/login' &&
to.path !== '/loginSite')
) {
next({
path: '/login'
})
// debugger
} else {
next()
}
})
/* eslint-disable no-new */
new Vue({
el: '#app',
router,
store,
template: '',
components: {
App
}
})
2、router.jsルーティング
import Vue from 'vue'
import Router from 'vue-router'
import dataCenter from './data_center' //
import subject from './subject/index.js' //
import pipe from './pipe/index.js' //
import screen from './screen/index.js' //
import desk from './desk/index.js' //
import businessManage from './business_management' //
import statisticalAnalysis from './statistical_analysis' //
import prevention from './prevention' //
/**
*
* @param {[type]} r [description]
* @return {[type]} [description]
*/
Vue.use(Router)
export default new Router({
// mode: 'history',
routes: [{
path: '/',
redirect() {
return '/login'
}
},
{
path: '/login',
name: ' ',
component: () => import('@/views/common/login.vue')
},
// /loginSite
{
path: '/welcome',
redirect() {
return '/loginSite'
}
},
{
path: '/loginSite',
component: () => import('@/views/common/loginSite.vue')
},
...subject,
...screen,
...desk,
...dataCenter,
...businessManage,
...statisticalAnalysis,
...pipe,
...prevention
],
// keep-alive
scrollBehavior(to, from, savedPosition) {
if (savedPosition) {
return savedPosition
} else {
if (from.meta.keepAlive) {
from.meta.savedPosition = document.body.scrollTop
}
return {
x: 0,
y: to.meta.savedPosition || 0
}
}
}
})