diff options
author | Helianthella <git@gumi.ca> | 2020-12-22 00:06:42 -0500 |
---|---|---|
committer | Helianthella <git@gumi.ca> | 2020-12-22 00:06:47 -0500 |
commit | b90bbeab7c1435518224496821ff3449476c458d (patch) | |
tree | e543aefb386a69bbe4b5d9fc73ebfb4c73c9361f /src/router | |
parent | f9c051e61da67b93ed3c9aba3d77bced80e1503e (diff) | |
download | website-b90bbeab7c1435518224496821ff3449476c458d.tar.gz website-b90bbeab7c1435518224496821ff3449476c458d.tar.bz2 website-b90bbeab7c1435518224496821ff3449476c458d.tar.xz website-b90bbeab7c1435518224496821ff3449476c458d.zip |
upgrade to Vue 3, switch to yarn
implies a slight refactor
Diffstat (limited to 'src/router')
-rw-r--r-- | src/router/index.ts | 71 | ||||
-rw-r--r-- | src/router/redirects.ts | 32 |
2 files changed, 103 insertions, 0 deletions
diff --git a/src/router/index.ts b/src/router/index.ts new file mode 100644 index 0000000..8165667 --- /dev/null +++ b/src/router/index.ts @@ -0,0 +1,71 @@ +import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router"; +import Home from "../views/Home.vue"; +import NotFound from "../views/NotFound.vue"; +import redirects from "./redirects"; + +const routes: Array<RouteRecordRaw> = [ + { + path: "/", + name: "home", + component: Home, + }, + { + path: "/news", + name: "news", + component: () => import(/* webpackChunkName: "news" */ "../views/NewsArchive.vue"), + }, + { + path: "/about", + name: "about", + component: () => import(/* webpackChunkName: "about" */ "../views/About.vue"), + }, + { + path: "/support", + name: "support", + component: () => import(/* webpackChunkName: "support" */ "../views/Support.vue"), + }, + { + path: "/recover/password:emailToken(.*)", + alias: ["/recover/username:emailToken(.*)"], + name: "account recovery", + component: () => import(/* webpackChunkName: "recovery" */ "../views/AccountRecovery.vue"), + }, + { + path: "/register", + name: "registration", + component: () => import(/* webpackChunkName: "registration" */ "../views/Registration.vue"), + }, + { + path: "/404:pathMatch(.*)", + alias: "/:pathMatch(.*)", + name: "not found", + component: NotFound, + }, + ...redirects, +]; + +const router = createRouter({ + history: createWebHistory(process.env.BASE_URL), + routes, +}); + +router.afterEach((to,) => { + const mainTitle = document.querySelector("#app > .content > h1"); + + // scroll to the title if we're below it + if (mainTitle) { + mainTitle.scrollIntoView({ + block: "nearest", // FIXME: weird behaviour in firefox! + inline: "nearest", + behavior: "smooth", + }); + } + + if (to.name && typeof to.name === "string" && to.path !== "/") { + document.title = `${process.env.VUE_APP_TITLE} - ${to.name[0].toUpperCase() + to.name.slice(1)}`; + } else { + document.title = process.env.VUE_APP_TITLE; + } +}); + +export default router; diff --git a/src/router/redirects.ts b/src/router/redirects.ts new file mode 100644 index 0000000..63860cf --- /dev/null +++ b/src/router/redirects.ts @@ -0,0 +1,32 @@ +// legacy paths from the PHP website + +const redirects = [ + { + path: "/index.php", + redirect: { name: "home" }, + }, + { + path: "/news-feed.php", + redirect: { name: "news" }, + }, + { + path: "/about.php", + redirect: { name: "about" }, + }, + { + path: "/registration.php", + redirect: { name: "registration" }, + }, + { + path: "/downloads.php", + redirect: () => { + self.location.href = "https://wiki.themanaworld.org/index.php/Downloads"; + } + }, + { + path: "/recover", + redirect: { name: "support" }, + }, +]; + +export default redirects; |