0f0384976481dfcbe590c547e1ac0b077e304622
[vchess.git] / client / src / router.js
1 import Vue from "vue";
2 import Router from "vue-router";
3 import Hall from "./views/Hall.vue";
4
5 Vue.use(Router);
6
7 function loadView(view) {
8 return () => import(/* webpackChunkName: "view-[request]" */ `@/views/${view}.vue`)
9 }
10
11 import { ajax } from "@/utils/ajax";
12 import { store } from "@/store";
13
14 export default 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 beforeEnter: (to, from, next) => {
35 ajax(
36 "/authenticate",
37 "GET",
38 {token: to.params["token"]},
39 (res) => {
40 store.state.user.id = res.id;
41 store.state.user.name = res.name;
42 store.state.user.email = res.email;
43 store.state.user.notify = res.notify;
44 // NOTE: mysid isn't cleared (required for potential game continuation)
45 next();
46 }
47 );
48 },
49 component: Hall,
50 //redirect: "/", //problem: redirection before end of AJAX request
51 },
52 // {
53 // path: "/about",
54 // name: "about",
55 // // route level code-splitting
56 // // this generates a separate chunk (about.[hash].js) for this route
57 // // which is lazy-loaded when the route is visited.
58 // component: loadView('About'),
59 // //function() {
60 // // return import(/* webpackChunkName: "about" */ "./views/About.vue");
61 // //}
62 // },
63 // TODO: gameRef, problemId: https://router.vuejs.org/guide/essentials/dynamic-matching.html
64 ]
65 });