deemixer/src/router.js

170 lines
2.9 KiB
JavaScript
Raw Normal View History

import Vue from 'vue'
import VueRouter from 'vue-router'
2020-07-28 19:39:44 +00:00
import { socket } from '@/utils/socket'
import EventBus from '@/utils/EventBus'
// Pages
import About from '@components/pages/About.vue'
import InfoArl from '@components/pages/InfoArl.vue'
import InfoSpotifyFeatures from '@components/pages/InfoSpotifyFeatures.vue'
import Artist from '@components/pages/Artist.vue'
import Charts from '@components/pages/Charts.vue'
import Errors from '@components/pages/Errors.vue'
import Favorites from '@components/pages/Favorites.vue'
import Home from '@components/pages/Home.vue'
import LinkAnalyzer from '@components/pages/LinkAnalyzer.vue'
import Search from '@components/pages/Search.vue'
import Settings from '@components/pages/Settings.vue'
import Tracklist from '@components/pages/Tracklist.vue'
Vue.use(VueRouter)
const routes = [
{
2020-07-28 19:39:44 +00:00
path: '/',
name: 'Home',
component: Home,
meta: {
notKeepAlive: true
}
2020-07-28 19:39:44 +00:00
},
{
path: '/tracklist/:type/:id',
name: 'Tracklist',
component: Tracklist
},
2020-07-28 19:39:44 +00:00
{
path: '/artist/:id',
name: 'Artist',
component: Artist
},
{
path: '/album/:id',
name: 'Album',
component: Tracklist
},
{
path: '/playlist/:id',
name: 'Playlist',
component: Tracklist
},
{
path: '/spotify-playlist/:id',
name: 'Spotify Playlist',
component: Tracklist
2020-07-28 19:39:44 +00:00
},
{
path: '/charts',
name: 'Charts',
component: Charts,
meta: {
notKeepAlive: true
}
},
{
path: '/favorites',
name: 'Favorites',
component: Favorites,
meta: {
notKeepAlive: true
}
},
{
path: '/errors',
name: 'Errors',
component: Errors
},
{
path: '/link-analyzer',
name: 'Link Analyzer',
component: LinkAnalyzer
},
{
path: '/about',
name: 'About',
component: About
},
{
path: '/arl',
name: 'ARL',
component: InfoArl
},
{
path: '/info-spotify',
name: 'Spotify Features',
component: InfoSpotifyFeatures
},
{
path: '/settings',
name: 'Settings',
component: Settings
},
{
path: '/search',
name: 'Search',
component: Search
},
2020-07-28 19:39:44 +00:00
// 404 client side
{
path: '*',
component: Home
}
]
const router = new VueRouter({
mode: 'history',
// linkActiveClass: 'open',
routes,
scrollBehavior(to, from, savedPosition) {
return { x: 0, y: 0 }
}
})
router.beforeEach((to, from, next) => {
let getTracklistParams = null
2020-07-28 19:39:44 +00:00
switch (to.name) {
case 'Artist':
getTracklistParams = {
2020-07-28 19:39:44 +00:00
type: 'artist',
id: to.params.id
}
2020-07-28 19:39:44 +00:00
break
case 'Tracklist':
getTracklistParams = {
2020-07-28 19:39:44 +00:00
type: to.params.type,
id: to.params.id
}
break
case 'Album':
getTracklistParams = {
type: 'album',
id: to.params.id
}
break
case 'Playlist':
getTracklistParams = {
type: 'playlist',
id: to.params.id
}
break
case 'Spotify Playlist':
getTracklistParams = {
type: 'spotifyplaylist',
id: to.params.id
}
break
2020-07-28 19:39:44 +00:00
default:
break
}
if (getTracklistParams) {
socket.emit('getTracklist', getTracklistParams)
}
next()
})
export default router