From 9bba1fa55e7111769cc6dc3bc5e2f32b4a6c2088 Mon Sep 17 00:00:00 2001 From: pnoker Date: Sun, 26 Jan 2020 20:26:04 +0800 Subject: [PATCH] . --- src/router/router.js | 87 ++++++++++---------------------------------- 1 file changed, 19 insertions(+), 68 deletions(-) diff --git a/src/router/router.js b/src/router/router.js index b3c5404..5e90a7d 100644 --- a/src/router/router.js +++ b/src/router/router.js @@ -1,73 +1,24 @@ -import Vue from 'vue' import VueRouter from 'vue-router' -import Home from '../views/Home.vue' -import Things from '../views/Things.vue' -import Template from '../views/Template.vue' -import Now from '../views/Now.vue' -import History from '../views/History.vue' -import Alarm from '../views/Alarm.vue' -import Label from '../views/Label.vue' -import Picture from '../views/Picture.vue' -import Video from '../views/Video.vue' -import About from '../views/About.vue' +import PageRouter from './page/' +import ViewsRouter from './views/' -Vue.use(VueRouter) +let router = new VueRouter({ + 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 + } + } + }, + routes: [] +}); -const routes = [ - { - path: '/', - name: 'home', - component: Home - }, - { - path: '/things', - name: 'things', - component: Things - }, - { - path: '/template', - name: 'template', - component: Template - }, - { - path: '/now', - name: 'now', - component: Now - }, - { - path: '/history', - name: 'history', - component: History - }, - { - path: '/alarm', - name: 'alarm', - component: Alarm - }, - { - path: '/label', - name: 'label', - component: Label - }, - { - path: '/picture', - name: 'picture', - component: Picture - }, - { - path: '/video', - name: 'video', - component: Video - }, - { - path: '/about', - name: 'about', - component: About - } -] - -const router = new VueRouter({ - routes -}) +router.addRoutes([...PageRouter, ...ViewsRouter]); export default router