Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
boco-frontend
Manage
Activity
Members
Labels
Plan
Issues
21
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
idatt2106_2022_02
boco-frontend
Commits
eb695a36
Commit
eb695a36
authored
2 years ago
by
Titus Netland
Browse files
Options
Downloads
Patches
Plain Diff
Routes alphabetized and added guardRoute to admin screen
parent
8bb5c465
No related branches found
Branches containing commit
No related tags found
1 merge request
!155
Routes alphabetized and added guardRoute to admin screen
Pipeline
#182354
passed with stage
in 1 minute and 13 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/router/index.js
+74
-64
74 additions, 64 deletions
src/router/index.js
with
74 additions
and
64 deletions
src/router/index.js
+
74
−
64
View file @
eb695a36
...
...
@@ -3,24 +3,32 @@ import { createRouter, createWebHistory } from "vue-router";
import
NotFound
from
"
@/views/NotFound.vue
"
;
/**
* Guards routes. If token is null, no user is logged in and only the
* login page and the register page will be accessible.
* Guards routes.
* 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
)
{
let
isAuthenticated
=
store
.
state
.
user
.
token
!=
null
;
if
(
isAuthenticated
)
{
next
();
// allow to enter route
}
else
{
next
(
"
/login
"
);
// go to
'/
login
';
next
(
"
/login
"
);
// go to
the
login
page
}
}
/**
* Guards routes 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
)
{
if
(
store
.
state
.
user
.
adminList
.
includes
(
parseInt
(
from
.
params
.
communityID
)))
next
();
else
next
(
"
/
"
);
next
();
// allow to enter route
else
next
(
"
/
"
);
// go to the home page
}
const
routes
=
[
{
path
:
"
/
"
,
...
...
@@ -28,37 +36,43 @@ const routes = [
component
:
()
=>
import
(
"
../views/CommunityViews/CommunityView.vue
"
),
},
{
path
:
"
/
help
"
,
name
:
"
help
"
,
component
:
()
=>
import
(
"
../views/
Help
View.vue
"
),
path
:
"
/
community/:communityID
"
,
name
:
"
communityHome
"
,
component
:
()
=>
import
(
"
../views/
CommunityViews/CommunityHome
View.vue
"
),
},
{
path
:
"
/
profile/:id
"
,
name
:
"
profil
e
"
,
component
:
()
=>
import
(
"
..
/views/
UserProfileViews/Profile
View.vue
"
),
beforeEnter
:
guardRoute
,
path
:
"
/
community/:communityID/admin
"
,
name
:
"
communityAdminPag
e
"
,
component
:
()
=>
import
(
"
@
/views/
CommunityViews/Admin
View.vue
"
),
beforeEnter
:
[
guardRoute
,
isAdmin
],
},
{
path
:
"
/
profile/history
"
,
name
:
"
history
"
,
component
:
()
=>
import
(
"
../views/
UserProfileViews/RentHistory
View.vue
"
),
path
:
"
/
community/:communityID/memberlist
"
,
name
:
"
memberlist
"
,
component
:
()
=>
import
(
"
../views/
CommunityViews/MemberList
View.vue
"
),
beforeEnter
:
guardRoute
,
},
{
path
:
"
/
profile/communities
"
,
name
:
"
myC
ommunit
i
es
"
,
component
:
()
=>
import
(
"
../views/
UserProfile
Views/
My
Communit
i
esView.vue
"
),
path
:
"
/
community/:communityID/private/join
"
,
name
:
"
c
ommunit
yRequ
es
t
"
,
component
:
()
=>
import
(
"
../views/
Community
Views/Communit
yRequ
es
t
View.vue
"
),
beforeEnter
:
guardRoute
,
},
{
path
:
"
/
register
"
,
name
:
"
register
"
,
component
:
()
=>
import
(
"
../views/
UserAuthViews/Register
View.vue
"
),
path
:
"
/
help
"
,
name
:
"
help
"
,
component
:
()
=>
import
(
"
../views/
Help
View.vue
"
),
},
{
path
:
"
/messages
"
,
name
:
"
messages
"
,
component
:
()
=>
import
(
"
../views/ChatViews/ChatView.vue
"
),
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
,
},
{
...
...
@@ -67,33 +81,17 @@ const routes = [
component
:
()
=>
import
(
"
../views/UserAuthViews/LoginView.vue
"
),
},
{
path
:
"
/
newPassword
"
,
name
:
"
newPassword
"
,
component
:
()
=>
import
(
"
../views/
UserAuthViews/NewPasswordView
"
),
path
:
"
/
messages
"
,
name
:
"
messages
"
,
component
:
()
=>
import
(
"
../views/
ChatViews/ChatView.vue
"
),
beforeEnter
:
guardRoute
,
},
{
path
:
"
/searchItemList
"
,
name
:
"
searchItemList
"
,
component
:
()
=>
import
(
"
../views/ItemViews/SearchItemListView.vue
"
),
},
{
path
:
"
/resetPassword
"
,
name
:
"
resetPassword
"
,
component
:
()
=>
import
(
"
../views/UserAuthViews/ResetPasswordView.vue
"
),
},
{
path
:
"
/newCommunity
"
,
name
:
"
newCommunity
"
,
component
:
()
=>
import
(
"
../views/CommunityViews/NewCommunityView.vue
"
),
beforeEnter
:
guardRoute
,
},
{
path
:
"
/community/:communityID/memberlist
"
,
name
:
"
memberlist
"
,
component
:
()
=>
import
(
"
../views/CommunityViews/MemberListView.vue
"
),
beforeEnter
:
guardRoute
,
},
{
path
:
"
/newItem
"
,
name
:
"
newItem
"
,
...
...
@@ -101,45 +99,57 @@ const routes = [
beforeEnter
:
guardRoute
,
},
{
path
:
"
/community/:communityID
"
,
name
:
"
communityHome
"
,
component
:
()
=>
import
(
"
../views/CommunityViews/CommunityHomeView.vue
"
),
path
:
"
/newPassword
"
,
name
:
"
newPassword
"
,
component
:
()
=>
import
(
"
../views/UserAuthViews/NewPasswordView
"
),
beforeEnter
:
guardRoute
,
},
{
path
:
"
/
community/:communityID/private/join
"
,
name
:
"
communityRequest
"
,
component
:
()
=>
import
(
"
../views/
CommunityViews/CommunityRequest
View.vue
"
),
path
:
"
/
profile/:id
"
,
name
:
"
profile
"
,
component
:
()
=>
import
(
"
../views/
UserProfileViews/Profile
View.vue
"
),
beforeEnter
:
guardRoute
,
},
{
path
:
"
/test
"
,
name
:
"
test
"
,
component
:
()
=>
import
(
"
../views/TestView.vue
"
),
path
:
"
/profile/communities
"
,
name
:
"
myCommunities
"
,
component
:
()
=>
import
(
"
../views/UserProfileViews/MyCommunitiesView.vue
"
),
beforeEnter
:
guardRoute
,
},
{
path
:
"
/
community/:communityID/admin
"
,
name
:
"
CommunityAdminView
"
,
component
:
()
=>
import
(
"
@
/views/
CommunityViews/Admin
View.vue
"
),
beforeEnter
:
isAdmin
,
path
:
"
/
profile/history
"
,
name
:
"
history
"
,
component
:
()
=>
import
(
"
..
/views/
UserProfileViews/RentHistory
View.vue
"
),
beforeEnter
:
guardRoute
,
},
{
path
:
"
/itempage/:id
"
,
name
:
"
ItemInfo
"
,
component
:
()
=>
import
(
"
../views/RentingViews/ItemInfoPageView.vue
"
),
beforeEnter
:
guardRoute
,
path
:
"
/register
"
,
name
:
"
register
"
,
component
:
()
=>
import
(
"
../views/UserAuthViews/RegisterView.vue
"
),
},
{
path
:
"
/item/:id/edit
"
,
name
:
"
editItem
"
,
component
:
()
=>
import
(
"
../views/ItemViews/EditItemView.vue
"
),
path
:
"
/resetPassword
"
,
name
:
"
resetPassword
"
,
component
:
()
=>
import
(
"
../views/UserAuthViews/ResetPasswordView.vue
"
),
},
{
path
:
"
/searchItemList
"
,
name
:
"
searchItemList
"
,
component
:
()
=>
import
(
"
../views/ItemViews/SearchItemListView.vue
"
),
},
{
path
:
"
/test
"
,
name
:
"
test
"
,
component
:
()
=>
import
(
"
../views/TestView.vue
"
),
beforeEnter
:
guardRoute
,
},
{
path
:
"
/user/userItems
"
,
name
:
"
U
serItems
"
,
name
:
"
u
serItems
"
,
component
:
()
=>
import
(
"
../views/UserProfileViews/UserItemsView.vue
"
),
beforeEnter
:
guardRoute
,
},
// Make sure it's your last route definition
{
path
:
"
/:pathMatch(.*)*
"
,
name
:
"
not-found
"
,
component
:
NotFound
},
];
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment