Commit 74f459ea authored by Phil Hughes's avatar Phil Hughes

Fix repository Vue router not working for routes without /-/

Closes https://gitlab.com/gitlab-org/gitlab/issues/202049
parent 95edb274
...@@ -28,8 +28,8 @@ export default function setupVueRepositoryList() { ...@@ -28,8 +28,8 @@ export default function setupVueRepositoryList() {
}, },
}); });
router.afterEach(({ params: { pathMatch } }) => { router.afterEach(({ params: { path } }) => {
setTitle(pathMatch, ref, fullName); setTitle(path, ref, fullName);
}); });
const breadcrumbEl = document.getElementById('js-repo-breadcrumb'); const breadcrumbEl = document.getElementById('js-repo-breadcrumb');
...@@ -48,9 +48,9 @@ export default function setupVueRepositoryList() { ...@@ -48,9 +48,9 @@ export default function setupVueRepositoryList() {
newDirPath, newDirPath,
} = breadcrumbEl.dataset; } = breadcrumbEl.dataset;
router.afterEach(({ params: { pathMatch = '/' } }) => { router.afterEach(({ params: { path = '/' } }) => {
updateFormAction('.js-upload-blob-form', uploadPath, pathMatch); updateFormAction('.js-upload-blob-form', uploadPath, path);
updateFormAction('.js-create-dir-form', newDirPath, pathMatch); updateFormAction('.js-create-dir-form', newDirPath, path);
}); });
// eslint-disable-next-line no-new // eslint-disable-next-line no-new
...@@ -61,7 +61,7 @@ export default function setupVueRepositoryList() { ...@@ -61,7 +61,7 @@ export default function setupVueRepositoryList() {
render(h) { render(h) {
return h(Breadcrumbs, { return h(Breadcrumbs, {
props: { props: {
currentPath: this.$route.params.pathMatch, currentPath: this.$route.params.path,
canCollaborate: parseBoolean(canCollaborate), canCollaborate: parseBoolean(canCollaborate),
canEditTree: parseBoolean(canEditTree), canEditTree: parseBoolean(canEditTree),
newBranchPath, newBranchPath,
...@@ -84,7 +84,7 @@ export default function setupVueRepositoryList() { ...@@ -84,7 +84,7 @@ export default function setupVueRepositoryList() {
render(h) { render(h) {
return h(LastCommit, { return h(LastCommit, {
props: { props: {
currentPath: this.$route.params.pathMatch, currentPath: this.$route.params.path,
}, },
}); });
}, },
...@@ -100,7 +100,7 @@ export default function setupVueRepositoryList() { ...@@ -100,7 +100,7 @@ export default function setupVueRepositoryList() {
render(h) { render(h) {
return h(TreeActionLink, { return h(TreeActionLink, {
props: { props: {
path: historyLink + (this.$route.params.pathMatch || '/'), path: `${historyLink}/${this.$route.params.path || ''}`,
text: __('History'), text: __('History'),
}, },
}); });
...@@ -117,7 +117,7 @@ export default function setupVueRepositoryList() { ...@@ -117,7 +117,7 @@ export default function setupVueRepositoryList() {
render(h) { render(h) {
return h(TreeActionLink, { return h(TreeActionLink, {
props: { props: {
path: webIDEUrl(`/${projectPath}/edit/${ref}/-${this.$route.params.pathMatch || '/'}`), path: webIDEUrl(`/${projectPath}/edit/${ref}/-/${this.$route.params.path || ''}`),
text: __('Web IDE'), text: __('Web IDE'),
cssClass: 'qa-web-ide-button', cssClass: 'qa-web-ide-button',
}, },
...@@ -134,7 +134,7 @@ export default function setupVueRepositoryList() { ...@@ -134,7 +134,7 @@ export default function setupVueRepositoryList() {
el: directoryDownloadLinks, el: directoryDownloadLinks,
router, router,
render(h) { render(h) {
const currentPath = this.$route.params.pathMatch || '/'; const currentPath = this.$route.params.path || '/';
if (currentPath !== '/') { if (currentPath !== '/') {
return h(DirectoryDownloadLinks, { return h(DirectoryDownloadLinks, {
......
...@@ -13,10 +13,10 @@ export default { ...@@ -13,10 +13,10 @@ export default {
return { projectPath: '', loadingPath: null }; return { projectPath: '', loadingPath: null };
}, },
beforeRouteUpdate(to, from, next) { beforeRouteUpdate(to, from, next) {
this.preload(to.params.pathMatch, next); this.preload(to.params.path, next);
}, },
methods: { methods: {
preload(path, next) { preload(path = '/', next) {
this.loadingPath = path.replace(/^\//, ''); this.loadingPath = path.replace(/^\//, '');
return this.$apollo return this.$apollo
......
...@@ -12,11 +12,11 @@ export default function createRouter(base, baseRef) { ...@@ -12,11 +12,11 @@ export default function createRouter(base, baseRef) {
base: joinPaths(gon.relative_url_root || '', base), base: joinPaths(gon.relative_url_root || '', base),
routes: [ routes: [
{ {
path: `/-/tree/${escape(baseRef)}(/.*)?`, path: `(/-)?/tree/${escape(baseRef)}/:path*`,
name: 'treePath', name: 'treePath',
component: TreePage, component: TreePage,
props: route => ({ props: route => ({
path: route.params.pathMatch && (route.params.pathMatch.replace(/^\//, '') || '/'), path: route.params.path?.replace(/^\//, '') || '/',
}), }),
}, },
{ {
......
...@@ -18,7 +18,7 @@ export default () => { ...@@ -18,7 +18,7 @@ export default () => {
axios axios
.post(data.pathLocksToggle, { .post(data.pathLocksToggle, {
path: router.currentRoute.params.pathMatch.replace(/^\//, ''), path: router.currentRoute.params.path.replace(/^\//, ''),
}) })
.then(() => window.location.reload()) .then(() => window.location.reload())
.catch(() => { .catch(() => {
......
...@@ -6,6 +6,7 @@ describe('Repository router spec', () => { ...@@ -6,6 +6,7 @@ describe('Repository router spec', () => {
it.each` it.each`
path | component | componentName path | component | componentName
${'/'} | ${IndexPage} | ${'IndexPage'} ${'/'} | ${IndexPage} | ${'IndexPage'}
${'/tree/master'} | ${TreePage} | ${'TreePage'}
${'/-/tree/master'} | ${TreePage} | ${'TreePage'} ${'/-/tree/master'} | ${TreePage} | ${'TreePage'}
${'/-/tree/master/app/assets'} | ${TreePage} | ${'TreePage'} ${'/-/tree/master/app/assets'} | ${TreePage} | ${'TreePage'}
${'/-/tree/123/app/assets'} | ${null} | ${'null'} ${'/-/tree/123/app/assets'} | ${null} | ${'null'}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment