Experimental improved behavior of login/logout/multitabs
[vchess.git] / client / src / router.js
... / ...
CommitLineData
1import Vue from "vue";
2import Router from "vue-router";
3import Hall from "./views/Hall.vue";
4
5Vue.use(Router);
6
7function loadView(view) {
8 return () => import(/* webpackChunkName: "view-[request]" */ `@/views/${view}.vue`)
9}
10
11import { ajax } from "@/utils/ajax";
12import { store } from "@/store";
13
14const router = new Router({
15 routes: [
16 {
17 path: "/",
18 name: "hall",
19 component: Hall,
20 },
21 {
22 path: "/variants",
23 name: "variants",
24 component: loadView("Variants"),
25 },
26 {
27 path: "/variants/:vname([a-zA-Z0-9]+)",
28 name: "rules",
29 component: loadView("Rules"),
30 },
31 {
32 path: "/authenticate/:token",
33 name: "authenticate",
34 component: loadView("Auth"),
35 },
36 {
37 path: "/logout",
38 name: "logout",
39 component: loadView("Logout"),
40 },
41 {
42 path: "/mygames",
43 name: "mygames",
44 component: loadView("MyGames"),
45 },
46 {
47 path: "/game/:id",
48 name: "game",
49 component: loadView("Game"),
50 },
51 {
52 path: "/analyze/:vname([a-zA-Z0-9]+)",
53 name: "analyze",
54 component: loadView("Analyze"),
55 },
56 {
57 path: "/about",
58 name: "about",
59 component: loadView("About"),
60 },
61 ]
62});
63
64router.beforeEach((to, from, next) => {
65 window.scrollTo(0, 0);
66 if (!!store.state.conn) //uninitialized at first page
67 {
68 // Notify WebSockets server (TODO: path or fullPath?)
69 store.state.conn.send(JSON.stringify({code: "pagechange", page: to.path}));
70 }
71 next();
72});
73
74export default router;