diff --git a/src/components/CommunityComponents/CommunityHome.vue b/src/components/CommunityComponents/CommunityHome.vue index 2e09b5104951dba94cbb936cb63c1a5f9e4d70ff..57ba73f12d40228d70bfc16a3effe1dcb28524fe 100644 --- a/src/components/CommunityComponents/CommunityHome.vue +++ b/src/components/CommunityComponents/CommunityHome.vue @@ -164,7 +164,7 @@ export default { } }, goToItemInfoPage(item) { - this.$router.push("/itempage/" + item); + this.$router.push("/item/" + item); }, getItemPictures: async function (itemid) { let res = await getItemPictures(itemid); diff --git a/src/components/ItemComponents/EditItemForm.vue b/src/components/ItemComponents/EditItemForm.vue index 17f46207594dc9088e0903d7b4771f4f5359d664..23f9bdc9fb01f6654f94f808567961ed0e278b71 100644 --- a/src/components/ItemComponents/EditItemForm.vue +++ b/src/components/ItemComponents/EditItemForm.vue @@ -377,7 +377,7 @@ export default { this.initialItem.listingID, this.updatedItem.images ); - this.$router.push("/itempage/" + this.initialItem.listingID); + this.$router.push("/item/" + this.initialItem.listingID); } }, diff --git a/src/components/UserProfileComponents/UserProfile.vue b/src/components/UserProfileComponents/UserProfile.vue index b0f04486a49fb92fb80e17c6bd64dd7cc5728bab..2b79e9d1ef3a8e6ab2f2299761a288c1a1def7b6 100644 --- a/src/components/UserProfileComponents/UserProfile.vue +++ b/src/components/UserProfileComponents/UserProfile.vue @@ -45,7 +45,7 @@ > <li> <router-link - to="/user/userItems" + to="/profile/items" class="block py-2 px-4 text-sm text-gray-700 hover:bg-gray-100 dark:hover:bg-gray-600 dark:text-gray-200 dark:hover:text-white" >Mine gjenstander</router-link > diff --git a/src/router/index.js b/src/router/index.js index 076a261ab383ed4a778175b6da01ffe1de64542e..d3da75ae0cbae2ac6d2432d41d97add0f06aec5d 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -3,12 +3,12 @@ import { createRouter, createWebHistory } from "vue-router"; import NotFound from "@/views/NotFound.vue"; /** - * Guards routes. + * Guard route for logged-in users. * If token is null, no user is logged in and only the * login, register, reset password, help and listing of public groups and items pages will be accessible. * Without a token the user gets redirected to the login page when trying to access guard routed pages. */ -function guardRoute(to, from, next) { +function authGuardRoute(to, from, next) { let isAuthenticated = store.state.user.token != null; if (isAuthenticated) { next(); // allow to enter route @@ -18,10 +18,10 @@ function guardRoute(to, from, next) { } /** - * Guards routes for administartors. If token is null or + * Guards route for administartors. If token is null or * the user is not the administrator of the group, the user gets sent to the home page. */ -function isAdmin(to, from, next) { +function adminGuardRoute(to, from, next) { if (store.state.user.adminList.includes(parseInt(from.params.communityID))) next(); // allow to enter route else @@ -44,36 +44,36 @@ const routes = [ path: "/community/:communityID/admin", name: "communityAdminPage", component: () => import("@/views/CommunityViews/AdminView.vue"), - beforeEnter: [guardRoute, isAdmin], + beforeEnter: [authGuardRoute, adminGuardRoute], }, { path: "/community/:communityID/memberlist", name: "memberlist", component: () => import("../views/CommunityViews/MemberListView.vue"), - beforeEnter: guardRoute, + beforeEnter: authGuardRoute, }, { path: "/community/:communityID/private/join", name: "communityRequest", component: () => import("../views/CommunityViews/CommunityRequestView.vue"), - beforeEnter: guardRoute, + beforeEnter: authGuardRoute, }, { path: "/help", name: "help", component: () => import("../views/HelpView.vue"), }, + { + path: "/item/:id", + name: "itemInfo", + component: () => import("../views/RentingViews/ItemInfoPageView.vue"), + beforeEnter: authGuardRoute, + }, { path: "/item/:id/edit", name: "editItem", component: () => import("../views/ItemViews/EditItemView.vue"), - beforeEnter: guardRoute, - }, - { - path: "/itempage/:id", - name: "itemInfo", - component: () => import("../views/RentingViews/ItemInfoPageView.vue"), - beforeEnter: guardRoute, + beforeEnter: authGuardRoute, }, { path: "/login", @@ -84,43 +84,49 @@ const routes = [ path: "/messages", name: "messages", component: () => import("../views/ChatViews/ChatView.vue"), - beforeEnter: guardRoute, + beforeEnter: authGuardRoute, }, { path: "/newCommunity", name: "newCommunity", component: () => import("../views/CommunityViews/NewCommunityView.vue"), - beforeEnter: guardRoute, + beforeEnter: authGuardRoute, }, { path: "/newItem", name: "newItem", component: () => import("../views/ItemViews/NewItemView.vue"), - beforeEnter: guardRoute, + beforeEnter: authGuardRoute, }, { path: "/newPassword", name: "newPassword", component: () => import("../views/UserAuthViews/NewPasswordView"), - beforeEnter: guardRoute, + beforeEnter: authGuardRoute, }, { path: "/profile/:id", name: "profile", component: () => import("../views/UserProfileViews/ProfileView.vue"), - beforeEnter: guardRoute, + beforeEnter: authGuardRoute, }, { path: "/profile/communities", name: "myCommunities", component: () => import("../views/UserProfileViews/MyCommunitiesView.vue"), - beforeEnter: guardRoute, + beforeEnter: authGuardRoute, }, { path: "/profile/history", name: "history", component: () => import("../views/UserProfileViews/RentHistoryView.vue"), - beforeEnter: guardRoute, + beforeEnter: authGuardRoute, + }, + { + path: "/profile/items", + name: "userItems", + component: () => import("../views/UserProfileViews/UserItemsView.vue"), + beforeEnter: authGuardRoute, }, { path: "/register", @@ -141,17 +147,17 @@ const routes = [ path: "/test", name: "test", component: () => import("../views/TestView.vue"), - beforeEnter: guardRoute, - }, - { - path: "/user/userItems", - name: "userItems", - component: () => import("../views/UserProfileViews/UserItemsView.vue"), - beforeEnter: guardRoute, + beforeEnter: authGuardRoute, }, - // Make sure it's your last route definition - { path: "/:pathMatch(.*)*", name: "not-found", component: NotFound }, + /** + * Catch all for wrong/non-existing routes + * Must be last to catch all + */ + { path: "/:pathMatch(.*)*", + name: "not-found", + component: NotFound + }, ]; const router = createRouter({