Commit | Line | Data |
---|---|---|
625022fd BA |
1 | import Vue from "vue"; |
2 | import Router from "vue-router"; | |
cf2343ce | 3 | import Hall from "./views/Hall.vue"; |
625022fd BA |
4 | |
5 | Vue.use(Router); | |
6 | ||
7 | function loadView(view) { | |
8 | return () => import(/* webpackChunkName: "view-[request]" */ `@/views/${view}.vue`) | |
9 | } | |
10 | ||
1aeed627 BA |
11 | import { ajax } from "@/utils/ajax"; |
12 | import { store } from "@/store"; | |
13 | ||
625022fd BA |
14 | export default new Router({ |
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", | |
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 | } | |
43 | ); | |
44 | next(); | |
45 | }, | |
46 | redirect: "/", | |
47 | }, | |
48 | { | |
49 | path: "/logout", | |
50 | name: "logout", | |
51 | beforeEnter: (to, from, next) => { | |
52 | ajax( | |
53 | "/logout", | |
54 | "GET", | |
55 | () => { | |
56 | store.state.user.id = 0; | |
57 | store.state.user.name = ""; //TODO: localStorage myId myname mysid ? | |
58 | } | |
59 | ); | |
60 | next(); | |
61 | }, | |
62 | redirect: "/", | |
63 | }, | |
ccd4a2b7 BA |
64 | // { |
65 | // path: "/about", | |
66 | // name: "about", | |
67 | // // route level code-splitting | |
68 | // // this generates a separate chunk (about.[hash].js) for this route | |
69 | // // which is lazy-loaded when the route is visited. | |
70 | // component: loadView('About'), | |
71 | // //function() { | |
72 | // // return import(/* webpackChunkName: "about" */ "./views/About.vue"); | |
73 | // //} | |
74 | // }, | |
8d61fc4a | 75 | // TODO: gameRef, problemId: https://router.vuejs.org/guide/essentials/dynamic-matching.html |
625022fd BA |
76 | ] |
77 | }); |