From f554b3c16b72b62fa2b5b7cf66f4f06b4a12336a Mon Sep 17 00:00:00 2001 From: Gamebrary Date: Wed, 4 Aug 2021 22:21:03 -0700 Subject: [PATCH] move routes to separate file and added placeholder and todos --- src/router.js | 186 ++++++------------------------------------------- src/routes.js | 188 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 211 insertions(+), 163 deletions(-) create mode 100644 src/routes.js diff --git a/src/router.js b/src/router.js index f4ffd838..17dbe474 100755 --- a/src/router.js +++ b/src/router.js @@ -1,170 +1,30 @@ import Vue from 'vue'; import Router from 'vue-router'; -import BoardPage from '@/pages/BoardPage'; -import AboutPage from '@/pages/AboutPage'; -import WallpapersPage from '@/pages/WallpapersPage'; -import PublicBoardsPage from '@/pages/PublicBoardsPage'; -import TagsPage from '@/pages/TagsPage'; -import NotesPage from '@/pages/NotesPage'; -import ReleasesPage from '@/pages/ReleasesPage'; -import AuthPage from '@/pages/AuthPage'; -import BoardsPage from '@/pages/BoardsPage'; -import PublicProfilesPage from '@/pages/PublicProfilesPage'; -import DevToolsPage from '@/pages/DevToolsPage'; -// TODO: finish homepage -// import HomePage from '@/pages/HomePage'; -import SettingsPage from '@/pages/SettingsPage'; -import ProfilePage from '@/pages/ProfilePage'; -import EditProfilePage from '@/pages/EditProfilePage'; -import PublicProfilePage from '@/pages/PublicProfilePage'; +import routes from '@/routes'; +import store from '@/store'; Vue.use(Router); -export default new Router({ +const router = new Router({ + // TODO: enable history mode // mode: 'history', - routes: [ - { - name: 'boards', - path: '/boards', - component: BoardsPage, - meta: { - title: 'Boards', - }, - }, - { - name: 'profiles', - path: '/profiles', - component: PublicProfilesPage, - meta: { - title: 'Boards', - public: true, - }, - }, - { - name: 'dev-tools', - path: '/dev-tools', - component: DevToolsPage, - meta: { - title: 'DevTools', - }, - }, - { - name: 'settings', - path: '/settings', - component: SettingsPage, - meta: { - title: 'Settings', - }, - }, - { - name: 'wallpapers', - path: '/wallpapers', - component: WallpapersPage, - meta: { - title: 'Wallpapers', - }, - }, - { - name: 'tags', - path: '/tags', - component: TagsPage, - meta: { - title: 'Tags', - }, - }, - { - name: 'notes', - path: '/notes', - component: NotesPage, - meta: { - title: 'Notes', - }, - }, - { - name: 'public-boards', - path: '/public-boards', - component: PublicBoardsPage, - meta: { - title: 'PublicBoards', - public: true, - }, - }, - { - name: 'profile', - path: '/profile', - component: ProfilePage, - meta: { - title: 'Profile', - }, - }, - { - name: 'edit-profile', - path: '/EditProfilePage', - component: EditProfilePage, - meta: { - title: 'Edit profile', - }, - }, - { - name: 'about', - path: '/about', - component: AboutPage, - meta: { - title: 'About', - }, - }, - { - name: 'releases', - path: '/releases', - component: ReleasesPage, - meta: { - title: 'Releases', - }, - }, - { - name: 'auth', - path: '/auth', - component: AuthPage, - meta: { - title: 'Auth', - }, - children: [ - { - name: 'auth-provider', - path: ':provider', - component: AuthPage, - }, - ], - }, - { - path: '/board/:id', - name: 'board', - component: BoardPage, - }, - { - path: '/b/:id', - name: 'public-board', - component: BoardPage, - meta: { - public: true, - }, - }, - { - path: '/:userName', - name: 'public-profile', - component: PublicProfilePage, - meta: { - public: true, - }, - }, - { - name: 'home', - path: '/', - component: BoardsPage, - meta: { - title: 'Home', - public: true, - }, - }, - ], + routes, }); + +// TODO: add navigation guards when trying to access private routes. + +// router.beforeEach((to, from, next) => { +// if (to.meta.public || store.state.user) next(); +// +// if (!to.meta.public && !store.state.user) { +// console.log('not allowed'); +// +// next({ name: 'auth' }); +// } +// +// next(); +// // if (to.name !== 'Login' && !isAuthenticated) next({ name: 'Login' }) +// // else next() +// }); + +export default router; diff --git a/src/routes.js b/src/routes.js new file mode 100644 index 00000000..a59f1bf2 --- /dev/null +++ b/src/routes.js @@ -0,0 +1,188 @@ +import AboutPage from '@/pages/AboutPage'; +import AuthPage from '@/pages/AuthPage'; +import BoardPage from '@/pages/BoardPage'; +import BoardsPage from '@/pages/BoardsPage'; +import DevToolsPage from '@/pages/DevToolsPage'; +import EditProfilePage from '@/pages/EditProfilePage'; +// import HomePage from '@/pages/HomePage'; +import NotFoundPage from '@/pages/NotFoundPage'; +import NotesPage from '@/pages/NotesPage'; +import ProfilePage from '@/pages/ProfilePage'; +import PublicBoardsPage from '@/pages/PublicBoardsPage'; +import PublicProfilePage from '@/pages/PublicProfilePage'; +import PublicProfilesPage from '@/pages/PublicProfilesPage'; +import PrivacyPolicyPage from '@/pages/PrivacyPolicyPage'; +import ReleasesPage from '@/pages/ReleasesPage'; +import SettingsPage from '@/pages/SettingsPage'; +import TagsPage from '@/pages/TagsPage'; +import TermsPage from '@/pages/TermsPage'; +import WallpapersPage from '@/pages/WallpapersPage'; + +const routes = [ + { + name: 'boards', + path: '/boards', + component: BoardsPage, + meta: { + title: 'Boards', + }, + }, + { + name: 'profiles', + path: '/profiles', + component: PublicProfilesPage, + meta: { + title: 'Boards', + public: true, + }, + }, + { + name: 'dev-tools', + path: '/dev-tools', + component: DevToolsPage, + meta: { + title: 'DevTools', + }, + }, + { + name: 'settings', + path: '/settings', + component: SettingsPage, + meta: { + title: 'Settings', + }, + }, + { + name: 'wallpapers', + path: '/wallpapers', + component: WallpapersPage, + meta: { + title: 'Wallpapers', + }, + }, + { + name: 'tags', + path: '/tags', + component: TagsPage, + meta: { + title: 'Tags', + }, + }, + { + name: 'notes', + path: '/notes', + component: NotesPage, + meta: { + title: 'Notes', + }, + }, + { + name: 'public-boards', + path: '/public-boards', + component: PublicBoardsPage, + meta: { + title: 'PublicBoards', + public: true, + }, + }, + { + name: 'profile', + path: '/profile', + component: ProfilePage, + meta: { + title: 'Profile', + }, + }, + { + name: 'edit-profile', + path: '/EditProfilePage', + component: EditProfilePage, + meta: { + title: 'Edit profile', + }, + }, + { + name: 'about', + path: '/about', + component: AboutPage, + meta: { + title: 'About', + }, + }, + { + name: 'releases', + path: '/releases', + component: ReleasesPage, + meta: { + title: 'Releases', + }, + }, + { + name: 'auth', + path: '/auth', + component: AuthPage, + meta: { + title: 'Auth', + public: true, + }, + children: [ + { + name: 'auth-provider', + path: ':provider', + component: AuthPage, + }, + ], + }, + { + path: '/board/:id', + name: 'board', + component: BoardPage, + }, + { + path: '/b/:id', + name: 'public-board', + component: BoardPage, + meta: { + public: true, + }, + }, + { + path: '/:userName', + name: 'public-profile', + component: PublicProfilePage, + meta: { + public: true, + }, + }, + { + path: '/privacy-policy', + name: 'privacy-policy-page', + component: PrivacyPolicyPage, + meta: { + public: true, + }, + }, + { + path: '/terms', + name: 'terms', + component: TermsPage, + meta: { + public: true, + }, + }, + { + name: 'home', + path: '/', + component: BoardsPage, + meta: { + title: 'Home', + public: true, + }, + }, + { + path: '*', + component: NotFoundPage, + }, +]; + +export default routes;