Always use a static back route (#2028)

Fixes: https://github.com/woodpecker-ci/woodpecker/issues/1998

---------

Co-authored-by: 6543 <6543@obermui.de>
This commit is contained in:
Robert Kaussow 2023-07-24 20:06:26 +02:00 committed by GitHub
parent c0216deb43
commit 2e954801b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 17 additions and 21 deletions

View file

@ -0,0 +1,9 @@
import { RouteLocationRaw, useRouter } from 'vue-router';
export function useRouteBack(to: RouteLocationRaw) {
const router = useRouter();
return async () => {
await router.replace(to);
};
}

View file

@ -1,13 +0,0 @@
import { RouteLocationRaw, useRouter } from 'vue-router';
export function useRouteBackOrDefault(to: RouteLocationRaw) {
const router = useRouter();
return async () => {
if ((window.history.state as { back: string }).back === null) {
await router.replace(to);
return;
}
router.back();
};
}

View file

@ -37,7 +37,7 @@ import useApiClient from '~/compositions/useApiClient';
import { useAsyncAction } from '~/compositions/useAsyncAction';
import useNotifications from '~/compositions/useNotifications';
import { useRepoSearch } from '~/compositions/useRepoSearch';
import { useRouteBackOrDefault } from '~/compositions/useRouteBackOrDefault';
import { useRouteBack } from '~/compositions/useRouteBack';
import { Repo } from '~/lib/api/types';
const router = useRouter();
@ -62,5 +62,5 @@ const { doSubmit: activateRepo, isLoading: isActivatingRepo } = useAsyncAction(a
await router.push({ name: 'repo', params: { repoId: _repo.id } });
});
const goBack = useRouteBackOrDefault({ name: 'repos' });
const goBack = useRouteBack({ name: 'repos' });
</script>

View file

@ -25,7 +25,7 @@ import Tab from '~/components/layout/scaffold/Tab.vue';
import OrgSecretsTab from '~/components/org/settings/OrgSecretsTab.vue';
import { inject } from '~/compositions/useInjectProvide';
import useNotifications from '~/compositions/useNotifications';
import { useRouteBackOrDefault } from '~/compositions/useRouteBackOrDefault';
import { useRouteBack } from '~/compositions/useRouteBack';
const notifications = useNotifications();
const router = useRouter();
@ -41,5 +41,5 @@ onMounted(async () => {
}
});
const goBack = useRouteBackOrDefault({ name: 'repos-owner' });
const goBack = useRouteBack({ name: 'org' });
</script>

View file

@ -49,7 +49,7 @@ import GeneralTab from '~/components/repo/settings/GeneralTab.vue';
import RegistriesTab from '~/components/repo/settings/RegistriesTab.vue';
import SecretsTab from '~/components/repo/settings/SecretsTab.vue';
import useNotifications from '~/compositions/useNotifications';
import { useRouteBackOrDefault } from '~/compositions/useRouteBackOrDefault';
import { useRouteBack } from '~/compositions/useRouteBack';
import { Repo, RepoPermissions } from '~/lib/api/types';
const notifications = useNotifications();
@ -73,5 +73,5 @@ onMounted(async () => {
}
});
const goBack = useRouteBackOrDefault({ name: 'repo' });
const goBack = useRouteBack({ name: 'repo' });
</script>

View file

@ -91,7 +91,7 @@ import { useAsyncAction } from '~/compositions/useAsyncAction';
import { useFavicon } from '~/compositions/useFavicon';
import useNotifications from '~/compositions/useNotifications';
import usePipeline from '~/compositions/usePipeline';
import { useRouteBackOrDefault } from '~/compositions/useRouteBackOrDefault';
import { useRouteBack } from '~/compositions/useRouteBack';
import { Repo, RepoPermissions } from '~/lib/api/types';
import { usePipelineStore } from '~/store/pipelines';
@ -196,5 +196,5 @@ const activeTab = computed({
},
});
const goBack = useRouteBackOrDefault({ name: 'repo' });
const goBack = useRouteBack({ name: 'repo' });
</script>