add /friends page
This commit is contained in:
parent
c49a40df01
commit
157e47d3ef
6 changed files with 293 additions and 10 deletions
|
|
@ -1,29 +1,27 @@
|
|||
import {createRouter, createWebHistory} from 'vue-router'
|
||||
import Index from '@/views/Index.vue';
|
||||
import Dashboard from '@/views/Dashboard.vue';
|
||||
import Login from '@/views/Login.vue';
|
||||
import Register from '@/views/Register.vue';
|
||||
import store from '@/store';
|
||||
import Friends from "@/views/Friends.vue";
|
||||
|
||||
|
||||
const routes = [
|
||||
{path: '/', component: Index, meta: {requiresAuth: true}},
|
||||
{path: '/', component: Dashboard, meta: {requiresAuth: true}},
|
||||
{path: '/friends', component: Friends, meta: {requiresAuth: true}},
|
||||
{path: '/login', component: Login, meta: {requiresAuth: false}},
|
||||
{path: '/register', component: Register, meta: {requiresAuth: false}},
|
||||
]
|
||||
|
||||
const router = createRouter({
|
||||
// 4. Provide the history implementation to use. We are using the hash history for simplicity here.
|
||||
history: createWebHistory(),
|
||||
linkActiveClass: "active",
|
||||
routes, // short for `routes: routes`
|
||||
routes,
|
||||
})
|
||||
|
||||
router.beforeEach((to/*, from*/) => {
|
||||
// instead of having to check every route record with
|
||||
// to.matched.some(record => record.meta.requiresAuth)
|
||||
// if this route requires auth, check if logged in, if not, redirect to login page.
|
||||
if (to.meta.requiresAuth && !store.getters.isLoggedIn) {
|
||||
// this route requires auth, check if logged in
|
||||
// if not, redirect to login page.
|
||||
console.log("Not logged in, redirecting to login page")
|
||||
return {
|
||||
path: '/login',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue