2 import Router
from "vue-router";
3 import Hall
from "./views/Hall.vue";
7 function loadView(view
) {
8 return () => import(/* webpackChunkName: "view-[request]" */ `@/views/${view}.vue`)
11 import { ajax
} from "@/utils/ajax";
12 import { store
} from "@/store";
14 const router
= new Router({
24 component: loadView("Variants"),
27 path: "/variants/:vname([a-zA-Z0-9]+)",
29 component: loadView("Rules"),
32 path: "/authenticate/:token",
34 beforeEnter: (to
, from, next
) => {
38 {token: to
.params
["token"]},
40 if (!res
.errmsg
) //if not already logged in
42 store
.state
.user
.id
= res
.id
;
43 store
.state
.user
.name
= res
.name
;
44 store
.state
.user
.email
= res
.email
;
45 store
.state
.user
.notify
= res
.notify
;
46 localStorage
["myname"] = res
.name
;
47 localStorage
["myid"] = res
.id
;
49 // TODO: I don't like these 2 lines, "next('/')" should be enough
50 window
.location
= "/";
56 //redirect: "/", //problem: redirection before end of AJAX request
61 component: loadView("MyGames"),
66 component: loadView("Game"),
69 path: "/analyze/:vname([a-zA-Z0-9]+)",
71 component: loadView("Game"),
76 component: loadView("About"),
81 router
.beforeEach((to
, from, next
) => {
82 window
.scrollTo(0, 0);
83 if (!!store
.state
.conn
) //uninitialized at first page
85 // Notify WebSockets server (TODO: path or fullPath?)
86 store
.state
.conn
.send(JSON
.stringify({code: "pagechange", page: to
.path
}));
91 export default router
;