WIP MMCM
This commit is contained in:
20
src/router/guards/piniaCheck.js
Normal file
20
src/router/guards/piniaCheck.js
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import {useMMCMStore} from '../../stores/mmcm.js'
|
||||||
|
|
||||||
|
export default function (routeTo) {
|
||||||
|
|
||||||
|
const store = useMMCMStore()
|
||||||
|
|
||||||
|
if (routeTo.path === '/delivery-option-step-1') {
|
||||||
|
return store.street !== '' && store.city !== '' && store.zipCode !== '';
|
||||||
|
|
||||||
|
} else if (routeTo.path === '/delivery-option-step-2') {
|
||||||
|
return store.withPrescription !== null
|
||||||
|
|
||||||
|
} else if (routeTo.path === '/delivery-option-step-3') {
|
||||||
|
return store.idProduct !== null
|
||||||
|
} else if (routeTo.path === '/delivery-option-summary') {
|
||||||
|
return store.dateDelivery !== null
|
||||||
|
} else {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
import {createRouter, createWebHistory} from 'vue-router'
|
import {createRouter, createWebHistory} from 'vue-router'
|
||||||
|
|
||||||
|
import piniaCheck from "./guards/piniaCheck.js";
|
||||||
|
|
||||||
const routes = [
|
const routes = [
|
||||||
{
|
{
|
||||||
path: '/',
|
path: '/',
|
||||||
@@ -38,4 +40,16 @@ const router = createRouter({
|
|||||||
routes,
|
routes,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
router.beforeEach(async (to, from) => {
|
||||||
|
// canUserAccess() returns `true` or `false`
|
||||||
|
|
||||||
|
if (from.path === '/' || to.path === '/') {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
const canAccessStep = piniaCheck(to)
|
||||||
|
if (!canAccessStep) return from.path
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
export default router
|
export default router
|
||||||
|
|||||||
Reference in New Issue
Block a user