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
;
54 //redirect: "/", //problem: redirection before end of AJAX request
59 component: loadView("Game"),
64 component: loadView("About"),
66 // TODO: myGames, problemId: https://router.vuejs.org/guide/essentials/dynamic-matching.html
70 router
.beforeEach((to
, from, next
) => {
71 window
.scrollTo(0, 0);
72 if (!!store
.state
.conn
) //uninitialized at first page
74 // Notify WebSockets server (TODO: path or fullPath?)
75 store
.state
.conn
.send(JSON
.stringify({code: "pagechange", page: to
.path
}));
78 // TODO?: redirect to current game (through GameStorage.getCurrent()) if any?
79 // (and if the URL doesn't already match it) (use next("/game/GID"))
80 //https://router.vuejs.org/guide/advanced/navigation-guards.html#global-before-guards
83 export default router
;