debian-mirror-gitlab/app/assets/javascripts/design_management/router/index.js

36 lines
931 B
JavaScript
Raw Normal View History

2020-05-24 23:13:21 +05:30
import $ from 'jquery';
import Vue from 'vue';
import VueRouter from 'vue-router';
import routes from './routes';
2020-06-23 00:09:42 +05:30
import { DESIGN_ROUTE_NAME } from './constants';
import { getPageLayoutElement } from '~/design_management/utils/design_management_utils';
import { DESIGN_DETAIL_LAYOUT_CLASSLIST } from '../constants';
2020-05-24 23:13:21 +05:30
Vue.use(VueRouter);
export default function createRouter(base) {
const router = new VueRouter({
base,
mode: 'history',
routes,
});
2020-06-23 00:09:42 +05:30
const pageEl = getPageLayoutElement();
2020-05-24 23:13:21 +05:30
2020-06-23 00:09:42 +05:30
router.beforeEach(({ meta: { el }, name }, _, next) => {
2020-05-24 23:13:21 +05:30
$(`#${el}`).tab('show');
2020-06-23 00:09:42 +05:30
// apply a fullscreen layout style in Design View (a.k.a design detail)
if (pageEl) {
if (name === DESIGN_ROUTE_NAME) {
pageEl.classList.add(...DESIGN_DETAIL_LAYOUT_CLASSLIST);
} else {
pageEl.classList.remove(...DESIGN_DETAIL_LAYOUT_CLASSLIST);
}
}
2020-05-24 23:13:21 +05:30
next();
});
return router;
}