Skip to content

Commit 337cda5

Browse files
authored
Merge pull request #7015 from LibreSign/backport/7013/stable33
[stable33] fix: vue router 5 non path params
2 parents 2c6b3e2 + ff1b834 commit 337cda5

4 files changed

Lines changed: 19 additions & 6 deletions

File tree

src/App.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,15 @@ import LeftSidebar from './components/LeftSidebar/LeftSidebar.vue'
3737
import RightSidebar from './components/RightSidebar/RightSidebar.vue'
3838
import DefaultPageError from './views/DefaultPageError.vue'
3939
40+
import { initialActionCode, ACTION_CODES } from './helpers/ActionMapping'
4041
import LogoLibreSign from '../img/logo-gray.svg'
4142
4243
const route = useRoute()
4344
const loading = ref(false)
4445
4546
const isRoot = computed(() => route.path === '/')
4647
const isSignExternalPage = computed(() => route.path.startsWith('/p/'))
47-
const isDoNothingError = computed(() => (route.params?.action as number | undefined) === 2000)
48+
const isDoNothingError = computed(() => initialActionCode.value === ACTION_CODES.DO_NOTHING)
4849
const showLeftSidebar = computed(() => !route.matched.some(record => record.meta?.hideLeftSidebar === true))
4950
</script>
5051

src/helpers/ActionMapping.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
55

6+
import { ref } from '@vue/reactivity'
7+
68
interface ActionCodes {
79
REDIRECT: number
810
CREATE_ACCOUNT: number
@@ -53,6 +55,14 @@ export const ACTION_CODE_TO_ROUTE: Readonly<ActionCodeToRoute> = Object.freeze({
5355
[ACTION_CODES.INCOMPLETE_SETUP]: 'Incomplete',
5456
})
5557

58+
/**
59+
* Shared reactive ref for the initial action code injected by the server
60+
* (#initial-state-libresign-action). Written once by router.ts beforeEach,
61+
* read by App.vue. Lives here (not in router.ts) to avoid App.vue triggering
62+
* the router module's side effects (createRouter, generateUrl) on import.
63+
*/
64+
export const initialActionCode = ref(0)
65+
5666
export const REQUIREMENT_TO_MODAL: Readonly<RequirementToModal> = Object.freeze({
5767
identificationDocuments: 'uploadDocuments',
5868
emailCode: 'emailToken',

src/router/router.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { createRouter, createWebHistory, type Router, type RouteRecordRaw } from
88
import { loadState } from '@nextcloud/initial-state'
99
import { getRootUrl, generateUrl } from '@nextcloud/router'
1010

11+
import { initialActionCode } from '../helpers/ActionMapping'
1112
import { isExternal } from '../helpers/isExternal'
1213
import { selectAction } from '../helpers/SelectAction'
1314

@@ -212,7 +213,7 @@ router.beforeEach((to, from, next) => {
212213
let action
213214
if (actionElement) {
214215
const actionValue = loadState('libresign', 'action', 0)
215-
to.params.action = String(actionValue)
216+
initialActionCode.value = actionValue
216217
action = selectAction(actionValue, to, from)
217218
document.querySelector('#initial-state-libresign-action')?.remove()
218219
}

src/tests/App.spec.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import { beforeEach, describe, expect, it, vi } from 'vitest'
77
import { mount } from '@vue/test-utils'
88

9+
import { initialActionCode, ACTION_CODES } from '../helpers/ActionMapping'
10+
911
type RouteState = {
1012
path: string
1113
name: string | undefined
@@ -56,6 +58,7 @@ describe('App', () => {
5658
routeState.name = 'fileslist'
5759
routeState.params = {}
5860
routeState.matched = []
61+
initialActionCode.value = 0
5962
})
6063

6164
it('shows left sidebar on regular internal routes', () => {
@@ -182,8 +185,8 @@ describe('App', () => {
182185
expect(wrapper.find('.nc-content').classes()).not.toContain('sign-external-page')
183186
})
184187

185-
it('shows DefaultPageError when action param is 2000', () => {
186-
routeState.params = { action: 2000 }
188+
it('shows DefaultPageError when initial action code is DO_NOTHING (2000)', () => {
189+
initialActionCode.value = ACTION_CODES.DO_NOTHING
187190

188191
const wrapper = mount(App, {
189192
global: {
@@ -203,8 +206,6 @@ describe('App', () => {
203206
})
204207

205208
it('does not show DefaultPageError on normal routes', () => {
206-
routeState.params = {}
207-
208209
const wrapper = mount(App, {
209210
global: {
210211
stubs: {

0 commit comments

Comments
 (0)