Browse Source

Adding new routing logic ... broken for the moment

kb/add-usage-guide
Matthew Aaron Raymer 2 years ago
parent
commit
39f2d73007
  1. 1
      src/main.ts
  2. 20
      src/router/index.ts
  3. 13
      src/store/app.ts

1
src/main.ts

@ -1,6 +1,5 @@
import { createPinia } from "pinia"; import { createPinia } from "pinia";
import { createApp } from "vue"; import { createApp } from "vue";
import { useAppStore } from "./store/app";
import App from "./App.vue"; import App from "./App.vue";
import "./registerServiceWorker"; import "./registerServiceWorker";
import router from "./router"; import router from "./router";

20
src/router/index.ts

@ -1,5 +1,5 @@
import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router"; import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router";
import { useAccountStore } from "../store/account"; import { useAppStore } from "../store/app";
import HomeView from "../views/HomeView.vue"; import HomeView from "../views/HomeView.vue";
const routes: Array<RouteRecordRaw> = [ const routes: Array<RouteRecordRaw> = [
@ -111,13 +111,21 @@ const router = createRouter({
}); });
router.beforeEach(async (to) => { router.beforeEach(async (to) => {
// redirect to start page if no account // redirect to start page if app is uninitialized
const publicPages = ["/start", "/account", "/import-account"]; const publicPages = ["/start"];
const authRequired = !publicPages.includes(to.path); const authRequired = !publicPages.includes(to.path);
const authStore = useAccountStore();
if (authRequired && !authStore.account) { let return_path = "/start";
return "/start"; if (authRequired) {
switch (useAppStore().condition) {
case "uninitialized":
return_path = "/start";
break;
case "registering":
return_path = useAppStore().lastView;
break;
}
} }
return return_path;
}); });
export default router; export default router;

13
src/store/app.ts

@ -2,12 +2,17 @@
import { defineStore } from "pinia"; import { defineStore } from "pinia";
export const useAppStore = defineStore({ export const useAppStore = defineStore({
id: "account", id: "app",
state: () => ({ state: () => ({
condition: JSON.parse( condition: JSON.parse(
typeof localStorage["app_condition"] == "undefined" typeof localStorage["condition"] == "undefined"
? "uninitialized" ? "uninitialized"
: localStorage["app_condition"] : localStorage["condition"]
),
lastView: JSON.parse(
typeof localStorage["lastView"] == "undefined"
? "/start"
: localStorage["lastView"]
), ),
}), }),
getters: { getters: {
@ -15,7 +20,7 @@ export const useAppStore = defineStore({
}, },
actions: { actions: {
reset() { reset() {
localStorage.removeItem("app_condition"); localStorage.removeItem("condition");
}, },
}, },
}); });

Loading…
Cancel
Save