diff options
author | Vidhu Kant Sharma <vidhukant@vidhukant.com> | 2023-10-04 20:31:21 +0530 |
---|---|---|
committer | Vidhu Kant Sharma <vidhukant@vidhukant.com> | 2023-10-04 20:31:21 +0530 |
commit | 92fb85b8afaacc4a8b5dbb41eea2d0e35eeb6862 (patch) | |
tree | 1b7bd25a29d0751f3efbd5e1125a1b079a31045c /src/router/index.ts |
first commitv0.0.1
Diffstat (limited to 'src/router/index.ts')
-rw-r--r-- | src/router/index.ts | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/src/router/index.ts b/src/router/index.ts new file mode 100644 index 0000000..af8e2c5 --- /dev/null +++ b/src/router/index.ts @@ -0,0 +1,74 @@ +import { createRouter, createWebHistory } from 'vue-router' + +import Register from '../views/Register.vue' +import LogIn from '../views/LogIn.vue' +import HomeView from '../views/HomeView.vue' +import AllBrands from '../views/AllBrands.vue' +import AllCustomers from '../views/AllCustomers.vue' +import NewCustomer from '../views/NewCustomer.vue' +import AllItems from '../views/AllItems.vue' +import NewItem from '../views/NewItem.vue' + +const router = createRouter({ + history: createWebHistory(import.meta.env.BASE_URL), + routes: [ + { + path: '/register', + name: 'register', + component: Register, + meta: { isAuth: false } + }, + { + path: '/login', + name: 'log in', + component: LogIn, + meta: { isAuth: false } + }, + { + path: '/', + name: 'home', + component: HomeView, + meta: { isAuth: true } + }, + { + path: '/brand', + name: 'brand', + component: AllBrands, + meta: { isAuth: true } + }, + { + path: '/customer', + name: 'customer', + component: AllCustomers, + meta: { isAuth: true } + }, + { + path: '/customer/new', + name: 'new customer', + component: NewCustomer, + meta: { isAuth: true } + }, + { + path: '/item', + name: 'item', + component: AllItems, + meta: { isAuth: true } + }, + { + path: '/item/new', + name: 'new item', + component: NewItem, + meta: { isAuth: true } + } + ] +}) + +router.beforeEach((to, _, next) => { + if (to.meta.isAuth && !localStorage.getItem("authToken")) { + next("/login?redirected=true") + } else { + next() + } +}) + +export default router |