forked from CSGOWTF/csgowtf
upgrade from webpack to vite + typescript
This commit is contained in:
@@ -1,130 +0,0 @@
|
||||
import {createRouter, createWebHistory} from 'vue-router'
|
||||
|
||||
function lazyLoadView(view) {
|
||||
return () => import(`@/views/${view}.vue`)
|
||||
}
|
||||
|
||||
function lazyLoadComponent(view) {
|
||||
return () => import(`@/components/${view}.vue`)
|
||||
}
|
||||
|
||||
function lazyLoadErrorPages(view) {
|
||||
return () => import(`@/views/errorPages/${view}.vue`)
|
||||
}
|
||||
|
||||
const routes = [
|
||||
{
|
||||
path: '/',
|
||||
name: 'Home',
|
||||
components: {
|
||||
main: lazyLoadView('Home')
|
||||
}
|
||||
},
|
||||
{
|
||||
path: '/privacy-policy',
|
||||
name: 'PrivacyPolicy',
|
||||
components: {
|
||||
main: lazyLoadView('PrivacyPolicy')
|
||||
}
|
||||
},
|
||||
{
|
||||
path: '/matches',
|
||||
name: 'Explore',
|
||||
components: {
|
||||
main: lazyLoadView('Explore')
|
||||
}
|
||||
},
|
||||
{
|
||||
path: '/player/:id',
|
||||
name: 'Player',
|
||||
components: {
|
||||
main: lazyLoadView('Player'),
|
||||
},
|
||||
props: true
|
||||
},
|
||||
{
|
||||
path: '/match/:match_id',
|
||||
name: 'Match',
|
||||
components: {
|
||||
main: lazyLoadView('Match')
|
||||
},
|
||||
props: true,
|
||||
children: [
|
||||
{
|
||||
path: '',
|
||||
components: {
|
||||
score: lazyLoadComponent('ScoreTeam')
|
||||
}
|
||||
},
|
||||
{
|
||||
path: 'economy',
|
||||
components: {
|
||||
score: lazyLoadComponent('EqValueGraph')
|
||||
}
|
||||
},
|
||||
{
|
||||
path: 'details',
|
||||
components: {
|
||||
score: lazyLoadComponent('Details')
|
||||
}
|
||||
},
|
||||
{
|
||||
path: 'flashes',
|
||||
components: {
|
||||
score: lazyLoadComponent('FlashChart')
|
||||
}
|
||||
},
|
||||
{
|
||||
path: 'damage',
|
||||
components: {
|
||||
score: lazyLoadComponent('DamageSite')
|
||||
}
|
||||
},
|
||||
{
|
||||
path: 'chat',
|
||||
components: {
|
||||
score: lazyLoadComponent('MatchChatHistory')
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
path: '/404',
|
||||
name: '404',
|
||||
components: {
|
||||
main: lazyLoadErrorPages('404')
|
||||
}
|
||||
},
|
||||
{
|
||||
path: '/500',
|
||||
name: '500',
|
||||
components: {
|
||||
main: lazyLoadErrorPages('500')
|
||||
}
|
||||
},
|
||||
{
|
||||
path: '/502',
|
||||
name: '502',
|
||||
components: {
|
||||
main: lazyLoadErrorPages('502')
|
||||
}
|
||||
},
|
||||
{
|
||||
path: '/:pathMatch(.*)*',
|
||||
redirect: '/'
|
||||
}
|
||||
]
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(process.env.BASE_URL),
|
||||
routes,
|
||||
scrollBehavior(to, from, savedPosition) {
|
||||
if (savedPosition) {
|
||||
return savedPosition
|
||||
} else {
|
||||
return {x: 0, y: 0}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
export default router
|
||||
130
src/router/index.ts
Normal file
130
src/router/index.ts
Normal file
@@ -0,0 +1,130 @@
|
||||
import { createRouter, createWebHistory } from "vue-router";
|
||||
|
||||
function lazyLoadView(view: string) {
|
||||
return () => import(`/src/views/${view}.vue`);
|
||||
}
|
||||
|
||||
function lazyLoadErrorPages(view: string) {
|
||||
return () => import(`/src/views/errorPages/${view}.vue`);
|
||||
}
|
||||
|
||||
function lazyLoadComponent(view: string) {
|
||||
return () => import(`/src/components/${view}.vue`);
|
||||
}
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(import.meta.env.BASE_URL),
|
||||
routes: [
|
||||
{
|
||||
path: "/",
|
||||
name: "Home",
|
||||
components: {
|
||||
main: lazyLoadView("HomeView"),
|
||||
},
|
||||
},
|
||||
{
|
||||
path: "/privacy-policy",
|
||||
name: "PrivacyPolicy",
|
||||
components: {
|
||||
main: lazyLoadView("PrivacyPolicy"),
|
||||
},
|
||||
},
|
||||
{
|
||||
path: "/matches",
|
||||
name: "Explore",
|
||||
components: {
|
||||
main: lazyLoadView("ExploreView"),
|
||||
},
|
||||
},
|
||||
{
|
||||
path: "/player/:id",
|
||||
name: "Player",
|
||||
components: {
|
||||
main: lazyLoadView("PlayerView"),
|
||||
},
|
||||
props: true,
|
||||
},
|
||||
{
|
||||
path: "/match/:match_id",
|
||||
name: "Match",
|
||||
components: {
|
||||
main: lazyLoadView("MatchView"),
|
||||
},
|
||||
props: true,
|
||||
children: [
|
||||
{
|
||||
path: "",
|
||||
components: {
|
||||
score: lazyLoadComponent("ScoreTeam"),
|
||||
},
|
||||
},
|
||||
{
|
||||
path: "economy",
|
||||
components: {
|
||||
score: lazyLoadComponent("EqValueGraph"),
|
||||
},
|
||||
},
|
||||
{
|
||||
path: "details",
|
||||
components: {
|
||||
score: lazyLoadComponent("DetailsComponent"),
|
||||
},
|
||||
},
|
||||
{
|
||||
path: "flashes",
|
||||
components: {
|
||||
score: lazyLoadComponent("FlashChart"),
|
||||
},
|
||||
},
|
||||
{
|
||||
path: "damage",
|
||||
components: {
|
||||
score: lazyLoadComponent("DamageSite"),
|
||||
},
|
||||
},
|
||||
{
|
||||
path: "chat",
|
||||
components: {
|
||||
score: lazyLoadComponent("MatchChatHistory"),
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
path: "/404",
|
||||
name: "404",
|
||||
components: {
|
||||
main: lazyLoadErrorPages("404Page"),
|
||||
},
|
||||
},
|
||||
{
|
||||
path: "/500",
|
||||
name: "500",
|
||||
components: {
|
||||
main: lazyLoadErrorPages("500Page"),
|
||||
},
|
||||
},
|
||||
{
|
||||
path: "/502",
|
||||
name: "502",
|
||||
components: {
|
||||
main: lazyLoadErrorPages("502Page"),
|
||||
},
|
||||
},
|
||||
{
|
||||
path: "/:pathMatch(.*)*",
|
||||
redirect: "/",
|
||||
},
|
||||
],
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
scrollBehavior(to, from, savedPosition) {
|
||||
if (savedPosition) {
|
||||
return savedPosition;
|
||||
} else {
|
||||
return { x: 0, y: 0 };
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
export default router;
|
||||
Reference in New Issue
Block a user