Skip to content

Instantly share code, notes, and snippets.

@enif-lee
Created February 7, 2017 14:55
Show Gist options
  • Select an option

  • Save enif-lee/f4d72e793f546770f2877f9f87001dd6 to your computer and use it in GitHub Desktop.

Select an option

Save enif-lee/f4d72e793f546770f2877f9f87001dd6 to your computer and use it in GitHub Desktop.
vue.js router guard
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