2019-03-30 22:55:48 +00:00
|
|
|
import Vue from 'vue'
|
|
|
|
|
import Router from 'vue-router'
|
2020-01-02 12:18:43 +00:00
|
|
|
import { axios } from './plugins/axios'
|
2019-03-30 22:55:48 +00:00
|
|
|
|
|
|
|
|
import Home from '@/views/Home.vue'
|
|
|
|
|
import Summoner from '@/views/Summoner.vue'
|
2019-12-03 20:57:52 +00:00
|
|
|
import SummonerChampions from '@/views/SummonerChampions.vue'
|
2020-01-12 00:31:28 +00:00
|
|
|
import SummonerRecords from '@/views/SummonerRecords.vue'
|
2019-03-30 22:55:48 +00:00
|
|
|
|
|
|
|
|
Vue.use(Router)
|
|
|
|
|
|
2020-01-02 12:18:43 +00:00
|
|
|
const router = new Router({
|
2019-03-30 22:55:48 +00:00
|
|
|
mode: 'history',
|
|
|
|
|
base: process.env.BASE_URL,
|
|
|
|
|
routes: [
|
|
|
|
|
{
|
|
|
|
|
path: '/',
|
|
|
|
|
name: 'home',
|
2019-12-03 20:57:52 +00:00
|
|
|
component: Home,
|
|
|
|
|
meta: {
|
|
|
|
|
layout: 'Home'
|
|
|
|
|
}
|
2019-03-30 22:55:48 +00:00
|
|
|
},
|
|
|
|
|
{
|
2019-04-07 17:44:01 +00:00
|
|
|
path: '/summoner/:region/:name',
|
2019-03-30 22:55:48 +00:00
|
|
|
name: 'summoner',
|
|
|
|
|
component: Summoner
|
2019-12-03 20:57:52 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: '/summoner/:region/:name/champions',
|
|
|
|
|
name: 'summonerChampions',
|
|
|
|
|
component: SummonerChampions
|
|
|
|
|
},
|
2020-01-12 00:31:28 +00:00
|
|
|
{
|
|
|
|
|
path: '/summoner/:region/:name/records',
|
|
|
|
|
name: 'summonerRecords',
|
|
|
|
|
component: SummonerRecords
|
|
|
|
|
},
|
2019-03-30 22:55:48 +00:00
|
|
|
]
|
2020-01-02 12:18:43 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
router.beforeEach((to, from, next) => {
|
|
|
|
|
if (to.params.name !== from.params.name && from.name !== null) {
|
|
|
|
|
// Cancel old requests
|
|
|
|
|
const axiosCancel = axios.defaults.axiosSource.cancel
|
|
|
|
|
axiosCancel('Summoner changed')
|
|
|
|
|
|
|
|
|
|
// Update cancel token
|
|
|
|
|
const CancelToken = axios.CancelToken
|
|
|
|
|
const axiosSource = CancelToken.source()
|
|
|
|
|
axios.defaults.axiosSource = axiosSource
|
|
|
|
|
axios.defaults.cancelToken = axiosSource.token
|
|
|
|
|
}
|
|
|
|
|
next()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export default router
|