diff options
author | Ferdinand Thiessen <opensource@fthiessen.de> | 2024-06-18 11:56:07 +0200 |
---|---|---|
committer | Ferdinand Thiessen <opensource@fthiessen.de> | 2024-09-06 03:38:47 +0200 |
commit | f109c1a044c772b4827382c4b04d7928696f78fb (patch) | |
tree | efcc7508f047e191c9a5f6fb2003b0147aa5596c /apps | |
parent | 82a7a3971dff8f89d5292b16253b4e8266c42cd5 (diff) | |
download | nextcloud-server-f109c1a044c772b4827382c4b04d7928696f78fb.tar.gz nextcloud-server-f109c1a044c772b4827382c4b04d7928696f78fb.zip |
refactor(files): Make `RouterService` provide a protected getter for the router to allow injecting the `files_sharing` router
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Diffstat (limited to 'apps')
-rw-r--r-- | apps/files/src/main.ts | 2 | ||||
-rw-r--r-- | apps/files/src/services/RouterService.ts | 31 |
2 files changed, 17 insertions, 16 deletions
diff --git a/apps/files/src/main.ts b/apps/files/src/main.ts index f8741fca96e..99fe99422a8 100644 --- a/apps/files/src/main.ts +++ b/apps/files/src/main.ts @@ -50,6 +50,6 @@ Object.assign(window.OCA.Files.Settings, { Setting: SettingsModel }) const FilesAppVue = Vue.extend(FilesApp) new FilesAppVue({ - router: window.OCP.Files.Router.router, + router: (window.OCP.Files.Router as RouterService)._router, pinia, }).$mount('#content') diff --git a/apps/files/src/services/RouterService.ts b/apps/files/src/services/RouterService.ts index 0138939b1ba..4e2999b1d29 100644 --- a/apps/files/src/services/RouterService.ts +++ b/apps/files/src/services/RouterService.ts @@ -2,36 +2,37 @@ * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later */ -import type { Route } from 'vue-router' +import type { Route, Location } from 'vue-router' import type VueRouter from 'vue-router' -import type { Dictionary, Location } from 'vue-router/types/router' export default class RouterService { - private _router: VueRouter + // typescript compiles this to `#router` to make it private even in JS, + // but in TS it needs to be called without the visibility specifier + private router: VueRouter constructor(router: VueRouter) { - this._router = router + this.router = router } get name(): string | null | undefined { - return this._router.currentRoute.name + return this.router.currentRoute.name } - get query(): Dictionary<string | (string | null)[] | null | undefined> { - return this._router.currentRoute.query || {} + get query(): Record<string, string | (string | null)[] | null | undefined> { + return this.router.currentRoute.query || {} } - get params(): Dictionary<string> { - return this._router.currentRoute.params || {} + get params(): Record<string, string> { + return this.router.currentRoute.params || {} } /** * This is a protected getter only for internal use * @private */ - get router() { - return this._router + get _router() { + return this.router } /** @@ -42,7 +43,7 @@ export default class RouterService { * @see https://router.vuejs.org/guide/essentials/navigation.html#navigate-to-a-different-location */ goTo(path: string, replace = false): Promise<Route> { - return this._router.push({ + return this.router.push({ path, replace, }) @@ -59,11 +60,11 @@ export default class RouterService { */ goToRoute( name?: string, - params?: Dictionary<string>, - query?: Dictionary<string | (string | null)[] | null | undefined>, + params?: Record<string, string>, + query?: Record<string, string | (string | null)[] | null | undefined>, replace?: boolean, ): Promise<Route> { - return this._router.push({ + return this.router.push({ name, query, params, |