X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Frouter.js;h=ede2186bdd30f21b08afe1837165efd3a6d3bb2d;hb=714680114508183fba2c07231dbe8f90b5631b81;hp=380ccc6cd2575301da919dd85be5a487d7fa20a9;hpb=92a523d1a74cbabcfd7d6ade45f25fa622815f0b;p=vchess.git diff --git a/client/src/router.js b/client/src/router.js index 380ccc6c..ede2186b 100644 --- a/client/src/router.js +++ b/client/src/router.js @@ -5,7 +5,7 @@ import Hall from "./views/Hall.vue"; Vue.use(Router); function loadView(view) { - return () => import(/* webpackChunkName: "view-[request]" */ `@/views/${view}.vue`) + return () => import(/* webpackChunkName: "view-[request]" */ `@/views/${view}.vue`) } import { ajax } from "@/utils/ajax"; @@ -31,53 +31,34 @@ const router = new Router({ { path: "/authenticate/:token", name: "authenticate", - beforeEnter: (to, from, next) => { - ajax( - "/authenticate", - "GET", - {token: to.params["token"]}, - (res) => { - if (!res.errmsg) //if not already logged in - { - store.state.user.id = res.id; - store.state.user.name = res.name; - store.state.user.email = res.email; - store.state.user.notify = res.notify; - localStorage["myname"] = res.name; - localStorage["myid"] = res.id; - } - next("/"); - } - ); - }, - component: Hall, - //redirect: "/", //problem: redirection before end of AJAX request + component: loadView("Auth"), + }, + { + path: "/logout", + name: "logout", + component: loadView("Logout"), + }, + { + path: "/mygames", + name: "mygames", + component: loadView("MyGames"), }, { - path: "/game/:id", + path: "/game/:id([a-zA-Z0-9]+)", name: "game", component: loadView("Game"), }, + { + path: "/analyse/:vname([a-zA-Z0-9]+)", + name: "analyse", + component: loadView("Analyse"), + }, { path: "/about", name: "about", component: loadView("About"), }, - // TODO: myGames, problemId: https://router.vuejs.org/guide/essentials/dynamic-matching.html ] }); -router.beforeEach((to, from, next) => { - window.scrollTo(0, 0); - if (!!store.state.conn) //uninitialized at first page - { - // Notify WebSockets server (TODO: path or fullPath?) - store.state.conn.send(JSON.stringify({code: "pagechange", page: to.path})); - } - next(); - // TODO?: redirect to current game (through GameStorage.getCurrent()) if any? - // (and if the URL doesn't already match it) (use next("/game/GID")) - //https://router.vuejs.org/guide/advanced/navigation-guards.html#global-before-guards -}); - export default router;