diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/files/src/router/router.ts | 8 | ||||
-rw-r--r-- | apps/files/src/views/Navigation.vue | 26 |
2 files changed, 23 insertions, 11 deletions
diff --git a/apps/files/src/router/router.ts b/apps/files/src/router/router.ts index 5bb8f90770b..4fec332cddf 100644 --- a/apps/files/src/router/router.ts +++ b/apps/files/src/router/router.ts @@ -19,9 +19,11 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ +import type { RawLocation, Route } from 'vue-router' + import { generateUrl } from '@nextcloud/router' import queryString from 'query-string' -import Router, { RawLocation, Route } from 'vue-router' +import Router from 'vue-router' import Vue from 'vue' import { ErrorHandler } from 'vue-router/types/router' @@ -46,10 +48,10 @@ const router = new Router({ { path: '/', // Pretending we're using the default view - redirect: { name: 'filelist' }, + redirect: { name: 'filelist', params: { view: 'files' } }, }, { - path: '/:view/:fileid?', + path: '/:view/:fileid(\\d+)?', name: 'filelist', props: true, }, diff --git a/apps/files/src/views/Navigation.vue b/apps/files/src/views/Navigation.vue index 9e7a630128e..0ed8d7d7a44 100644 --- a/apps/files/src/views/Navigation.vue +++ b/apps/files/src/views/Navigation.vue @@ -25,9 +25,9 @@ <template #list> <NcAppNavigationItem v-for="view in parentViews" :key="view.id" - :allow-collapse="true" + allow-collapse :data-cy-files-navigation-item="view.id" - :exact="true" + :exact="useExactRouteMatching(view)" :icon="view.iconClass" :name="view.name" :open="isExpanded(view)" @@ -41,7 +41,7 @@ <NcAppNavigationItem v-for="child in childViews[view.id]" :key="child.id" :data-cy-files-navigation-item="child.id" - :exact="true" + :exact-path="true" :icon="child.iconClass" :name="child.name" :to="generateToNavigation(child)"> @@ -128,7 +128,7 @@ export default { }, currentView(): View { - return this.views.find(view => view.id === this.currentViewId) + return this.views.find(view => view.id === this.currentViewId)! }, views(): View[] { @@ -145,19 +145,19 @@ export default { }) }, - childViews(): View[] { + childViews(): Record<string, View[]> { return this.views // filter parent views .filter(view => !!view.parent) // create a map of parents and their children .reduce((list, view) => { - list[view.parent] = [...(list[view.parent] || []), view] + list[view.parent!] = [...(list[view.parent!] || []), view] // Sort children by order - list[view.parent].sort((a, b) => { + list[view.parent!].sort((a, b) => { return a.order - b.order }) return list - }, {}) + }, {} as Record<string, View[]>) }, }, @@ -180,6 +180,16 @@ export default { }, methods: { + /** + * Only use exact route matching on routes with child views + * Because if a view does not have children (like the files view) then multiple routes might be matched for it + * Like for the 'files' view this does not work because of optional 'fileid' param so /files and /files/1234 are both in the 'files' view + * @param view The view to check + */ + useExactRouteMatching(view: View) { + return this.childViews[view.id]?.length > 0 + }, + showView(view: View) { // Closing any opened sidebar window?.OCA?.Files?.Sidebar?.close?.() |