Created
February 7, 2017 14:55
-
-
Save enif-lee/41666f8158a73567818bd37f020127a9 to your computer and use it in GitHub Desktop.
vue.js router guard
This file contains hidden or 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 VueRouter from 'vue-router' | |
| import firebase from 'firebase' | |
| import signIn from './sign-in.vue' | |
| Vue.use(VueRouter); | |
| const router = new VueRouter({ | |
| routes: [ | |
| { | |
| path: '/', | |
| template: '<div>Main</div>' | |
| }, | |
| { | |
| path: '/login', | |
| component: signIn | |
| }, | |
| { | |
| path: '/tasks', component: { | |
| template: '<div>Task</div>' | |
| } | |
| }, | |
| { | |
| path: '/chats', component: { | |
| template: '<div>Chat</div>' | |
| } | |
| } | |
| ], | |
| beforeEach: (to, from, next) => { | |
| if (firebase.auth().currentUser == null && to.path.toLowerCase() != '/login') next('/login'); | |
| next(); | |
| } | |
| }); | |
| export default router; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment