From f517bc37f766bee93a23122448c0a7bb5af9665d Mon Sep 17 00:00:00 2001 From: Devlin Junker Date: Sun, 4 Dec 2022 09:10:04 -0800 Subject: split out routing and add another route Signed-off-by: Devlin Junker --- src/App.vue | 2 +- src/components/Sidebar.vue | 8 ++++---- src/components/Starred.vue | 25 +++++++++++++++++++++++++ src/main.js | 19 ++----------------- src/routes/index.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 76 insertions(+), 22 deletions(-) create mode 100644 src/components/Starred.vue create mode 100644 src/routes/index.js diff --git a/src/App.vue b/src/App.vue index 076fed19c..0f5c1a0dc 100644 --- a/src/App.vue +++ b/src/App.vue @@ -2,7 +2,7 @@ - + diff --git a/src/components/Sidebar.vue b/src/components/Sidebar.vue index c51ea16ac..7e88d97ff 100644 --- a/src/components/Sidebar.vue +++ b/src/components/Sidebar.vue @@ -27,7 +27,7 @@ - + @@ -118,7 +118,7 @@ + :to="{ name: ROUTES.EXPLORE }"> @@ -140,7 +140,7 @@ import NcAppNavigationNewItem from '@nextcloud/vue/dist/Components/NcAppNavigati import NcCounterBubble from '@nextcloud/vue/dist/Components/NcCounterBubble.js' import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton.js' -// import { ROUTES } from '../routes.js' +import { ROUTES } from '../routes' import { ACTIONS, AppState } from '../store' import AddFeed from './AddFeed.vue' @@ -174,7 +174,7 @@ export default Vue.extend({ data: () => { return { showAddFeed: false, - // ROUTES + ROUTES, } }, computed: { diff --git a/src/components/Starred.vue b/src/components/Starred.vue new file mode 100644 index 000000000..d1117d137 --- /dev/null +++ b/src/components/Starred.vue @@ -0,0 +1,25 @@ + + + diff --git a/src/main.js b/src/main.js index 6dac8fd5a..2f11a8216 100644 --- a/src/main.js +++ b/src/main.js @@ -1,11 +1,10 @@ import Vue from 'vue' -import App from './App.vue' import VueRouter from 'vue-router' -import Explore from './components/Explore.vue' -import { generateUrl } from '@nextcloud/router' import Vuex, { Store } from 'vuex' +import App from './App.vue' +import router from './routes' import mainStore from './store' import { Tooltip } from '@nextcloud/vue' @@ -20,20 +19,6 @@ Vue.use(VueRouter) Vue.directive('tooltip', Tooltip) -const routes = [ - { - name: 'explore', - path: '#explore', - component: Explore, - }, -] - -const router = new VueRouter({ - mode: 'history', - base: generateUrl('apps/news'), - routes, -}) - const store = new Store(mainStore) export default new Vue({ diff --git a/src/routes/index.js b/src/routes/index.js new file mode 100644 index 000000000..6ced33c49 --- /dev/null +++ b/src/routes/index.js @@ -0,0 +1,44 @@ +import Vue from 'vue' +import VueRouter from 'vue-router' + +import ExplorePanel from '../components/Explore' +import StarredPanel from '../components/Starred' + +export const ROUTES = { + EXPLORE: 'explore', + STARRED: 'starred', +} + +const getInitialRoute = function() { + // TODO: Fetch Recent route from Browser Session? + return ROUTES.EXPLORE +} + +const routes = [ + // using + // { path: '/collections/all', component: CollectionGeneral, alias: '/' }, + // instead of + { path: '/', redirect: getInitialRoute() }, + // would also be an option, but it currently does not work + // reliably with router-link due to + // https://github.com/vuejs/vue-router/issues/419 + { + name: ROUTES.EXPLORE, + path: '/explore', + component: ExplorePanel, + props: true, + }, + { + name: ROUTES.STARRED, + path: '/starred', + component: StarredPanel, + props: true, + }, +] + +Vue.use(VueRouter) + +export default new VueRouter({ + linkActiveClass: 'active', + routes, // short for `routes: routes` +}) -- cgit v1.2.3