-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fc6d9a9
commit 9e8931f
Showing
4 changed files
with
2,956 additions
and
1,775 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,58 @@ | ||
import Vue from 'vue'; | ||
import VueRouter from 'vue-router'; | ||
import Vue from "vue"; | ||
import VueRouter, { RouteConfig, Route } from "vue-router"; | ||
|
||
import Login from './views/Login.vue'; | ||
import Photos from './views/Photos.vue'; | ||
import Login from "./views/Login.vue"; | ||
import Photos from "./views/Photos.vue"; | ||
|
||
import store from './store'; | ||
import store from "./store"; | ||
|
||
Vue.use(VueRouter); | ||
|
||
const routes: VueRouter.RouteConfig[] = [ | ||
{ | ||
path: '/', | ||
name: 'photos', | ||
component: Photos, | ||
beforeEnter: (to: VueRouter.Route, from: VueRouter.Route, next: (path?: string) => void) => { | ||
if (store.state.accessToken === '') { | ||
next('/login'); | ||
} else { | ||
next(); | ||
} | ||
}, | ||
}, | ||
{ | ||
path: '/access_token*', | ||
beforeEnter: (to: VueRouter.Route, from: VueRouter.Route, next: (path?: string) => void) => { | ||
try { | ||
const match: RegExpMatchArray | null = to.path.match(/^\/access_token=(.+)$/); | ||
const token = (match as RegExpMatchArray)[1]; | ||
const routes: RouteConfig[] = [ | ||
{ | ||
path: "/", | ||
name: "photos", | ||
component: Photos, | ||
beforeEnter: (to: Route, from: Route, next: (path?: string) => void) => { | ||
if (store.state.accessToken === "") { | ||
next("/login"); | ||
} else { | ||
next(); | ||
} | ||
} | ||
}, | ||
{ | ||
path: "/access_token*", | ||
beforeEnter: (to: Route, from: Route, next: (path?: string) => void) => { | ||
try { | ||
const match: RegExpMatchArray | null = to.path.match( | ||
/^\/access_token=(.+)$/ | ||
); | ||
const token = (match as RegExpMatchArray)[1]; | ||
|
||
store.commit('SET_ACCESS_TOKEN', token); | ||
next('/'); | ||
} catch (e) { | ||
next('/login'); | ||
} | ||
}, | ||
}, | ||
{ | ||
path: '/logout', | ||
beforeEnter: (to: VueRouter.Route, from: VueRouter.Route, next: (path?: string) => void) => { | ||
store.commit('SET_ACCESS_TOKEN', ''); | ||
next('/login'); | ||
}, | ||
}, | ||
{ | ||
path: '/login', | ||
name: 'login', | ||
component: Login, | ||
}, | ||
store.commit("SET_ACCESS_TOKEN", token); | ||
next("/"); | ||
} catch (e) { | ||
next("/login"); | ||
} | ||
} | ||
}, | ||
{ | ||
path: "/logout", | ||
beforeEnter: (to: Route, from: Route, next: (path?: string) => void) => { | ||
store.commit("SET_ACCESS_TOKEN", ""); | ||
next("/login"); | ||
} | ||
}, | ||
{ | ||
path: "/login", | ||
name: "login", | ||
component: Login | ||
} | ||
]; | ||
|
||
const router = new VueRouter({ | ||
routes, | ||
routes | ||
}); | ||
|
||
export default router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.