From 40d69b9cce186a4b2c2dd50bec4859331223a1c2 Mon Sep 17 00:00:00 2001
From: Adam Procter <adamprocter@researchnot.es>
Date: Tue, 31 Aug 2021 14:31:47 +0100
Subject: [PATCH] guarded routes when you have no microcosm

---
 src/router/index.js | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/src/router/index.js b/src/router/index.js
index c71dfcc..4b4af3d 100644
--- a/src/router/index.js
+++ b/src/router/index.js
@@ -1,6 +1,17 @@
 import { createRouter, createWebHistory } from 'vue-router'
 import Start from '../views/Start.vue'
 
+function guardMyroute(to, from, next) {
+  var hasMicrocosm = false
+  if (localStorage.getItem('nogg_microcosm')) hasMicrocosm = true
+  else hasMicrocosm = false
+  if (hasMicrocosm) {
+    next() // allow to enter route
+  } else {
+    next('/') // go to '/'
+  }
+}
+
 const routes = [
   {
     path: '/',
@@ -19,6 +30,7 @@ const routes = [
   {
     path: '/collect',
     name: 'Collect',
+    beforeEnter: guardMyroute,
     // route level code-splitting
     // this generates a separate chunk (credits.[hash].js) for this route
     // which is lazy-loaded when the route is visited.
@@ -29,6 +41,7 @@ const routes = [
   {
     path: '/cards',
     name: 'Cards',
+    beforeEnter: guardMyroute,
     // route level code-splitting
     // this generates a separate chunk (credits.[hash].js) for this route
     // which is lazy-loaded when the route is visited.
-- 
GitLab