summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/repository/router.js
blob: b42a96a4ee2bff9c0fa73105b7528a5ef78d63eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import Vue from 'vue';
import VueRouter from 'vue-router';
import { joinPaths } from '../lib/utils/url_utility';
import IndexPage from './pages/index.vue';
import TreePage from './pages/tree.vue';

Vue.use(VueRouter);

export default function createRouter(base, baseRef) {
  return new VueRouter({
    mode: 'history',
    base: joinPaths(gon.relative_url_root || '', base),
    routes: [
      {
        path: '/',
        name: 'projectRoot',
        component: IndexPage,
      },
      {
        path: `/tree/${baseRef}(/.*)?`,
        name: 'treePath',
        component: TreePage,
        props: route => ({
          path: route.params.pathMatch,
        }),
        beforeEnter(to, from, next) {
          document
            .querySelectorAll('.js-hide-on-navigation')
            .forEach(el => el.classList.add('hidden'));

          next();
        },
      },
    ],
  });
}