deemixer/src/router.js

177 lines
3.3 KiB
JavaScript
Raw Normal View History

import Vue from 'vue'
import VueRouter from 'vue-router'
// Pages
2021-02-25 21:26:05 +00:00
//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'
import { fetchData } from '@/utils/api'
2021-03-12 19:26:45 +00:00
import EventBus from '@/utils/EventBus'
Vue.use(VueRouter)
const routes = [
{
2021-01-31 15:55:37 +00:00
path: window.location.pathname,
name: 'Home',
component: Home,
meta: {
notKeepAlive: true
}
2020-07-28 19:39:44 +00:00
},
{
2021-01-31 16:45:06 +00:00
path: '/tracklist/:type/:id',
2020-07-28 19:39:44 +00:00
name: 'Tracklist',
component: Tracklist
},
2020-07-28 19:39:44 +00:00
{
2021-01-31 16:45:06 +00:00
path: '/artist/:id',
2020-07-28 19:39:44 +00:00
name: 'Artist',
component: Artist,
meta: {
notKeepAlive: true
}
},
{
2021-01-31 16:45:06 +00:00
path: '/album/:id',
name: 'Album',
component: Tracklist
},
{
2021-01-31 16:45:06 +00:00
path: '/playlist/:id',
name: 'Playlist',
component: Tracklist
},
{
2021-01-31 16:45:06 +00:00
path: '/spotify-playlist/:id',
name: 'Spotify Playlist',
component: Tracklist
2020-07-28 19:39:44 +00:00
},
{
2021-01-31 16:45:06 +00:00
path: '/charts',
name: 'Charts',
component: Charts,
meta: {
notKeepAlive: true
}
},
{
2021-01-31 16:45:06 +00:00
path: '/favorites',
name: 'Favorites',
component: Favorites,
meta: {
notKeepAlive: true
}
},
{
2021-01-31 16:45:06 +00:00
path: '/errors',
name: 'Errors',
component: Errors
},
{
2021-01-31 16:45:06 +00:00
path: '/link-analyzer',
name: 'Link Analyzer',
component: LinkAnalyzer
},
2021-02-25 21:26:05 +00:00
/*{
2021-01-31 16:45:06 +00:00
path: '/about',
name: 'About',
component: About
2021-02-25 21:26:05 +00:00
},*/
{
2021-01-31 16:45:06 +00:00
path: '/info-arl',
name: 'ARL',
component: InfoArl
},
{
2021-01-31 16:45:06 +00:00
path: '/info-spotify',
name: 'Spotify Features',
component: InfoSpotifyFeatures
},
{
2021-01-31 16:45:06 +00:00
path: '/settings',
name: 'Settings',
component: Settings
},
{
2021-01-31 16:45:06 +00:00
path: '/search',
name: 'Search',
component: Search,
meta: {
notKeepAlive: true
}
},
2020-07-28 19:39:44 +00:00
// 404 client side
{
path: '*',
component: Home
}
]
const router = new VueRouter({
mode: 'history',
routes,
scrollBehavior(to, from, savedPosition) {
return { x: 0, y: 0 }
}
})
router.beforeEach((to, from, next) => {
2020-07-28 19:39:44 +00:00
switch (to.name) {
2021-03-12 19:26:45 +00:00
case 'Tracklist': {
// const getTracklistParams = {
// type: to.params.type,
// id: to.params.id
// }
console.warn('This should never happen.')
break
2021-03-12 19:26:45 +00:00
}
case 'Album': {
const getTracklistParams = {
type: 'album',
id: to.params.id
}
2021-03-12 19:26:45 +00:00
fetchData('getTracklist', getTracklistParams).then(albumData => {
EventBus.$emit('showAlbum', albumData)
})
break
2021-03-12 19:26:45 +00:00
}
case 'Playlist': {
const getTracklistParams = {
type: 'playlist',
id: to.params.id
}
2021-03-12 19:26:45 +00:00
fetchData('getTracklist', getTracklistParams).then(playlistData => {
EventBus.$emit('showPlaylist', playlistData)
})
break
2021-03-12 19:26:45 +00:00
}
case 'Spotify Playlist': {
const getTracklistParams = {
type: 'spotifyplaylist',
id: to.params.id
}
2021-03-12 19:26:45 +00:00
fetchData('getTracklist', getTracklistParams).then(spotifyPlaylistData => {
EventBus.$emit('showSpotifyPlaylist', spotifyPlaylistData)
})
break
2021-03-12 19:26:45 +00:00
}
2020-07-28 19:39:44 +00:00
default:
break
}
next()
})
export default router