2019-09-04 21:01:54 +05:30
|
|
|
import Vue from 'vue';
|
|
|
|
import VueRouter from 'vue-router';
|
2020-11-24 15:15:51 +05:30
|
|
|
import { escapeRegExp } from 'lodash';
|
2019-09-04 21:01:54 +05:30
|
|
|
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) {
|
2020-05-24 23:13:21 +05:30
|
|
|
const treePathRoute = {
|
|
|
|
component: TreePage,
|
|
|
|
props: route => ({
|
|
|
|
path: route.params.path?.replace(/^\//, '') || '/',
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
return new VueRouter({
|
|
|
|
mode: 'history',
|
|
|
|
base: joinPaths(gon.relative_url_root || '', base),
|
|
|
|
routes: [
|
|
|
|
{
|
2020-05-24 23:13:21 +05:30
|
|
|
name: 'treePathDecoded',
|
|
|
|
// Sometimes the ref needs decoding depending on how the backend sends it to us
|
|
|
|
path: `(/-)?/tree/${decodeURI(baseRef)}/:path*`,
|
|
|
|
...treePathRoute,
|
|
|
|
},
|
|
|
|
{
|
2019-09-04 21:01:54 +05:30
|
|
|
name: 'treePath',
|
2020-05-24 23:13:21 +05:30
|
|
|
// Support without decoding as well just in case the ref doesn't need to be decoded
|
2020-11-24 15:15:51 +05:30
|
|
|
path: `(/-)?/tree/${escapeRegExp(baseRef)}/:path*`,
|
2020-05-24 23:13:21 +05:30
|
|
|
...treePathRoute,
|
2019-09-04 21:01:54 +05:30
|
|
|
},
|
|
|
|
{
|
|
|
|
path: '/',
|
|
|
|
name: 'projectRoot',
|
|
|
|
component: IndexPage,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
}
|