Files
raven-client/ayanova/src/router.js
2019-07-09 23:20:32 +00:00

153 lines
4.0 KiB
JavaScript

import Vue from "vue";
import Router from "vue-router";
import Home from "./views/Home.vue";
import service from "./views/service.vue";
import dispatch from "./views/dispatch.vue";
import accounting from "./views/accounting.vue";
import administration from "./views/administration.vue";
import operations from "./views/operations.vue";
import notfound from "./views/notfound.vue";
Vue.use(Router);
/* Xeslint-disable */
// scrollBehavior:
// - only available in html5 history mode
// - defaults to no scroll behavior
// - return false to prevent scroll
const scrollBehavior = function(to, from, savedPosition) {
if (savedPosition) {
// savedPosition is only available for popstate navigations.
return savedPosition;
} else {
const position = {};
// scroll to anchor by returning the selector
if (to.hash) {
position.selector = to.hash;
// specify offset of the element
if (to.hash === "#anchor2") {
position.offset = { y: 100 };
}
if (document.querySelector(to.hash)) {
return position;
}
// if the returned position is falsy or an empty object,
// will retain current scroll position.
return false;
}
return new Promise(resolve => {
// check if any matched route config has meta that requires scrolling to top
if (to.matched.some(m => m.meta.scrollToTop)) {
// coords will be used if no selector is provided,
// or if the selector didn't match any element.
position.x = 0;
position.y = 0;
}
// wait for the out transition to complete (if necessary)
this.app.$root.$once("triggerScroll", () => {
// if the resolved position is falsy or an empty object,
// will retain current scroll position.
resolve(position);
});
});
}
};
export default new Router({
mode: "history",
base: process.env.BASE_URL,
scrollBehavior,
routes: [
{
path: "/login",
name: "login",
meta: { scrollToTop: true },
component: () =>
import(/* webpackChunkName: "login" */ "./views/login.vue")
},
{
path: "/",
name: "home",
meta: { scrollToTop: true },
component: Home
// ,
// beforeEnter(to, from, next) {
// store.state.tempsessionsettings = false;//here is a way to reset the temp session settings, but I'll likely do it through logout proces instead, keeping this for example purposes
// next();
// }
},
{
path: "/about",
name: "about",
// route level code-splitting
// this generates a separate chunk (about.[hash].js) for this route
// which is lazy-loaded when the route is visited.
component: () =>
import(/* webpackChunkName: "about" */ "./views/About.vue")
},
{
path: "/log",
name: "log",
component: () => import(/* webpackChunkName: "log" */ "./views/log.vue")
},
{
path: "/inventory",
name: "inventory",
component: () =>
import(/* webpackChunkName: "inventory" */ "./views/inventory.vue")
},
{
path: "/service",
name: "service",
component: service
},
{
path: "/dispatch",
name: "dispatch",
component: dispatch
},
{
path: "/accounting",
name: "accounting",
//meta: { scrollToTop: true },
component: accounting
},
{
path: "/admin",
name: "administration",
component: administration
},
{
path: "/ops",
name: "operations",
component: operations
},
{
path: "/inventory/widget/edit/:id",
name: "inventory-widget-edit",
component: () =>
import(/* webpackChunkName: "inventory-widget-edit" */ "./views/inventory-widget-edit.vue")
},
{
path: "/customize/:ayatype",
name: "customize",
component: () =>
import(/* webpackChunkName: "inventory-widget-edit" */ "./views/customize.vue")
},
{
path: "*",
name: "notfound",
component: notfound
}
]
});