This commit is contained in:
Jonathan Chevalier
2022-09-29 16:20:16 +02:00
parent 5192982555
commit efa0296c1d
2 changed files with 34 additions and 0 deletions

View 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
}
}

View File

@@ -1,5 +1,7 @@
import {createRouter, createWebHistory} from 'vue-router'
import piniaCheck from "./guards/piniaCheck.js";
const routes = [
{
path: '/',
@@ -38,4 +40,16 @@ const router = createRouter({
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