@@ -232,9 +232,21 @@ import { loadState } from '@nextcloud/initial-state'
232232import { t } from ' @nextcloud/l10n'
233233import moment from ' @nextcloud/moment'
234234import { generateOcsUrl } from ' @nextcloud/router'
235- import { computed , onBeforeMount , onMounted , onUnmounted , ref , watch } from ' vue'
235+ import {
236+ computed ,
237+ inject ,
238+ onBeforeMount ,
239+ onMounted ,
240+ onUnmounted ,
241+ ref ,
242+ watch ,
243+ } from ' vue'
236244import { defineComponent } from ' vue'
237- import { onBeforeRouteLeave , onBeforeRouteUpdate , useRoute } from ' vue-router'
245+ import {
246+ onBeforeRouteLeave ,
247+ onBeforeRouteUpdate ,
248+ routeLocationKey ,
249+ } from ' vue-router'
238250import NcAppContent from ' @nextcloud/vue/components/NcAppContent'
239251import NcButton from ' @nextcloud/vue/components/NcButton'
240252import NcDialog from ' @nextcloud/vue/components/NcDialog'
@@ -364,7 +376,8 @@ export default defineComponent({
364376 emits: [' update:form' , ' open-sharing' ],
365377
366378 setup(props , { emit }) {
367- const route = useRoute ()
379+ // Public submit app has no vue-router; inject returns null there.
380+ const route = inject (routeLocationKey , null )
368381 const title = ref (null )
369382 const formElement = ref <HTMLFormElement | null >(null )
370383 const questionRefs = ref <
@@ -545,9 +558,10 @@ export default defineComponent({
545558 })
546559
547560 const submissionId = computed <number | null >(() => {
548- const routeSubmissionId = Array .isArray (route .params .submissionId )
549- ? route .params .submissionId [0 ]
550- : route .params .submissionId
561+ const rawSubmissionId = route ?.params ?.submissionId
562+ const routeSubmissionId = Array .isArray (rawSubmissionId )
563+ ? rawSubmissionId [0 ]
564+ : rawSubmissionId
551565 const id =
552566 routeSubmissionId || loadState (formsAppName , ' submissionId' , null )
553567 return id ? parseInt (String (id ), 10 ) : null
@@ -1000,27 +1014,30 @@ export default defineComponent({
10001014 },
10011015 )
10021016
1003- onBeforeRouteUpdate (async () => {
1004- // This navigation guard is called when the route parameters changed (e.g. form hash)
1005- // continue with the navigation if there are no changes or the user confirms to leave the form
1006- if (await confirmLeaveForm ()) {
1007- return
1008- } else {
1009- // Otherwise cancel the navigation
1010- return false
1011- }
1012- })
1017+ // Navigation guards only work inside the routed Forms app, not the public submit entry.
1018+ if (! props .publicView ) {
1019+ onBeforeRouteUpdate (async () => {
1020+ // This navigation guard is called when the route parameters changed (e.g. form hash)
1021+ // continue with the navigation if there are no changes or the user confirms to leave the form
1022+ if (await confirmLeaveForm ()) {
1023+ return
1024+ } else {
1025+ // Otherwise cancel the navigation
1026+ return false
1027+ }
1028+ })
10131029
1014- onBeforeRouteLeave (async () => {
1015- // This navigation guard is called when the route changed and a new view should be shown
1016- // continue with the navigation if there are no changes or the user confirms to leave the form
1017- if (await confirmLeaveForm ()) {
1018- return
1019- } else {
1020- // Otherwise cancel the navigation
1021- return false
1022- }
1023- })
1030+ onBeforeRouteLeave (async () => {
1031+ // This navigation guard is called when the route changed and a new view should be shown
1032+ // continue with the navigation if there are no changes or the user confirms to leave the form
1033+ if (await confirmLeaveForm ()) {
1034+ return
1035+ } else {
1036+ // Otherwise cancel the navigation
1037+ return false
1038+ }
1039+ })
1040+ }
10241041
10251042 onMounted ((): void => {
10261043 window .addEventListener (' beforeunload' , beforeWindowUnload )
0 commit comments