Update packages versions
[vchess.git] / client / src / router.js
CommitLineData
625022fd
BA
1import Vue from "vue";
2import Router from "vue-router";
cf2343ce 3import Hall from "./views/Hall.vue";
625022fd
BA
4
5Vue.use(Router);
6
7function loadView(view) {
dac39588 8 return () => import(/* webpackChunkName: "view-[request]" */ `@/views/${view}.vue`)
625022fd
BA
9}
10
1aeed627
BA
11import { ajax } from "@/utils/ajax";
12import { store } from "@/store";
13
786e0065 14const router = new Router({
625022fd
BA
15 routes: [
16 {
17 path: "/",
cf2343ce
BA
18 name: "hall",
19 component: Hall,
625022fd 20 },
5b020e73
BA
21 {
22 path: "/variants",
23 name: "variants",
24 component: loadView("Variants"),
25 },
cf2343ce
BA
26 {
27 path: "/variants/:vname([a-zA-Z0-9]+)",
28 name: "rules",
29 component: loadView("Rules"),
30 },
1aeed627
BA
31 {
32 path: "/authenticate/:token",
33 name: "authenticate",
a3ac374b
BA
34 component: loadView("Auth"),
35 },
36 {
37 path: "/logout",
38 name: "logout",
39 component: loadView("Logout"),
1aeed627 40 },
afd3240d
BA
41 {
42 path: "/mygames",
43 name: "mygames",
44 component: loadView("MyGames"),
45 },
f7121527
BA
46 {
47 path: "/game/:id",
48 name: "game",
49 component: loadView("Game"),
50 },
afd3240d
BA
51 {
52 path: "/analyze/:vname([a-zA-Z0-9]+)",
53 name: "analyze",
652f40de 54 component: loadView("Analyze"),
afd3240d 55 },
92a523d1
BA
56 {
57 path: "/about",
58 name: "about",
59 component: loadView("About"),
60 },
625022fd
BA
61 ]
62});
786e0065
BA
63
64router.beforeEach((to, from, next) => {
92a523d1
BA
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 }
786e0065
BA
71 next();
72});
73
74export default router;