Files
mealie/frontend/src/routes/index.js
Hayden af41b08a60 Bug/fix infinite loop (#512)
* fix infinite loop with safe get method

* fix ingredients

Co-authored-by: hay-kot <hay-kot@pm.me>
2021-06-13 14:07:58 -08:00

59 lines
1.5 KiB
JavaScript

import Page404 from "@/pages/404Page";
import { adminRoutes } from "./admin";
import { authRoutes } from "./auth";
import { recipeRoutes } from "./recipes";
import { mealRoutes } from "./meal";
import { generalRoutes } from "./general";
import { store } from "@/store";
import VueRouter from "vue-router";
import VueI18n from "@/i18n";
import Vuetify from "@/plugins/vuetify";
import Vue from "vue";
import i18n from "@/i18n.js";
export const routes = [
...generalRoutes,
adminRoutes,
...authRoutes,
...mealRoutes,
...recipeRoutes,
{ path: "/page-not-found", component: Page404 },
{ path: "*", component: Page404 },
];
const router = new VueRouter({
base: process.env.BASE_URL,
routes,
mode: process.env.NODE_ENV === "production" ? "history" : "hash",
scrollBehavior() {
return { x: 0, y: 0 };
},
});
const DEFAULT_TITLE = "Mealie";
const TITLE_SEPARATOR = "|";
const TITLE_SUFFIX = " " + TITLE_SEPARATOR + " " + DEFAULT_TITLE;
router.afterEach(to => {
Vue.nextTick(async () => {
if (typeof to.meta.title === "function") {
const title = await to.meta.title(to);
document.title = title + TITLE_SUFFIX;
} else {
document.title = i18n.t(to.meta.title) ? i18n.t(to.meta.title) + TITLE_SUFFIX : DEFAULT_TITLE;
}
});
});
function loadLocale() {
VueI18n.locale = store.getters.getActiveLang;
Vuetify.framework.lang.current = store.getters.getActiveLang;
}
router.beforeEach((__, _, next) => {
loadLocale();
next();
});
export { router };