You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RouterService.ts 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /**
  2. * @copyright Copyright (c) 2023 John Molakvoæ <skjnldsv@protonmail.com>
  3. *
  4. * @author John Molakvoæ <skjnldsv@protonmail.com>
  5. *
  6. * @license AGPL-3.0-or-later
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as
  10. * published by the Free Software Foundation, either version 3 of the
  11. * License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. import type { Route } from 'vue-router'
  23. import type VueRouter from 'vue-router'
  24. import type { Dictionary, Location } from 'vue-router/types/router'
  25. export default class RouterService {
  26. private _router: VueRouter
  27. constructor(router: VueRouter) {
  28. this._router = router
  29. }
  30. /**
  31. * Trigger a route change on the files app
  32. *
  33. * @param path the url path, eg: '/trashbin?dir=/Deleted'
  34. * @param replace replace the current history
  35. * @see https://router.vuejs.org/guide/essentials/navigation.html#navigate-to-a-different-location
  36. */
  37. goTo(path: string, replace = false): Promise<Route> {
  38. return this._router.push({
  39. path,
  40. replace,
  41. })
  42. }
  43. /**
  44. * Trigger a route change on the files App
  45. *
  46. * @param name the route name
  47. * @param params the route parameters
  48. * @param query the url query parameters
  49. * @param replace replace the current history
  50. * @see https://router.vuejs.org/guide/essentials/navigation.html#navigate-to-a-different-location
  51. */
  52. goToRoute(
  53. name?: string,
  54. params?: Dictionary<string>,
  55. query?: Dictionary<string | (string | null)[] | null | undefined>,
  56. replace?: boolean,
  57. ): Promise<Route> {
  58. return this._router.push({
  59. name,
  60. query,
  61. params,
  62. replace,
  63. } as Location)
  64. }
  65. }