Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
DMD-4470/final/src/router.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
52 lines (45 sloc)
927 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Vue from 'vue' | |
import Router from 'vue-router' | |
import store from './store'; | |
/** | |
* Don't forget to import your views here: | |
*/ | |
import Home from './views/Home.vue' | |
import About from './views/About.vue' | |
import Login from './views/Login.vue' | |
import Profile from './views/Profile.vue' | |
Vue.use(Router) | |
const router = new Router({ | |
mode: 'history', | |
base: process.env.BASE_URL, | |
routes: [ | |
{ | |
path: '/login', | |
name: 'login', | |
component: Login | |
}, | |
{ | |
path: '/', | |
name: 'home', | |
component: Home | |
}, | |
{ | |
path: '/about', | |
name: 'about', | |
component: About | |
}, | |
{ | |
path: '/profile', | |
name: 'profile', | |
component: Profile | |
} | |
] | |
}); | |
/** | |
* Authentication Check | |
*/ | |
router.beforeEach((to, from, next) => { | |
if (to.name !== 'login' && !store.getters.isAuthenticated) next({ name: 'login' }) | |
else next() | |
}) | |
export default router; |