summaryrefslogtreecommitdiff
path: root/src/router/index.ts
blob: 816566752f2bed52c8f5ec530761057a20d2d22b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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;