2019-05-20 04:41:28 -04:00
|
|
|
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) {
|
2020-05-14 11:08:14 -04:00
|
|
|
const treePathRoute = {
|
|
|
|
component: TreePage,
|
|
|
|
props: route => ({
|
|
|
|
path: route.params.path?.replace(/^\//, '') || '/',
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
|
2019-05-20 04:41:28 -04:00
|
|
|
return new VueRouter({
|
|
|
|
mode: 'history',
|
|
|
|
base: joinPaths(gon.relative_url_root || '', base),
|
|
|
|
routes: [
|
|
|
|
{
|
2020-05-14 11:08:14 -04:00
|
|
|
name: 'treePathDecoded',
|
|
|
|
// Sometimes the ref needs decoding depending on how the backend sends it to us
|
|
|
|
path: `(/-)?/tree/${decodeURI(baseRef)}/:path*`,
|
|
|
|
...treePathRoute,
|
|
|
|
},
|
|
|
|
{
|
2019-05-20 04:41:28 -04:00
|
|
|
name: 'treePath',
|
2020-05-14 11:08:14 -04:00
|
|
|
// Support without decoding as well just in case the ref doesn't need to be decoded
|
|
|
|
path: `(/-)?/tree/${baseRef}/:path*`,
|
|
|
|
...treePathRoute,
|
2019-05-20 04:41:28 -04:00
|
|
|
},
|
2019-05-24 05:39:18 -04:00
|
|
|
{
|
|
|
|
path: '/',
|
|
|
|
name: 'projectRoot',
|
|
|
|
component: IndexPage,
|
|
|
|
},
|
2019-05-20 04:41:28 -04:00
|
|
|
],
|
|
|
|
});
|
|
|
|
}
|