Improve navigation
This commit is contained in:
parent
d5945d675e
commit
6a22d99c17
12 changed files with 198 additions and 72 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import Vue from 'vue'
|
||||
import VueRouter from 'vue-router'
|
||||
//import Home from '../components/Home.vue'
|
||||
import Chat from '../components/Chat.vue'
|
||||
import Login from '../components/Login.vue'
|
||||
|
||||
|
|
@ -8,6 +9,11 @@ Vue.use(VueRouter)
|
|||
const routes = [
|
||||
{
|
||||
path: '/',
|
||||
name: 'Home',
|
||||
component: Chat
|
||||
},
|
||||
{
|
||||
path: '/room/',
|
||||
name: 'Chat',
|
||||
component: Chat
|
||||
},
|
||||
|
|
@ -25,6 +31,7 @@ const routes = [
|
|||
},
|
||||
{
|
||||
path: '/join/',
|
||||
name: 'Join',
|
||||
component: () => import('../components/Join.vue'),
|
||||
props: true
|
||||
},
|
||||
|
|
@ -32,13 +39,21 @@ const routes = [
|
|||
|
||||
const router = new VueRouter({
|
||||
routes
|
||||
})
|
||||
});
|
||||
|
||||
router.beforeEach((to, from, next) => {
|
||||
const publicPages = ['/login'];
|
||||
const authRequired = !publicPages.includes(to.path) && !to.path.startsWith('/join/');
|
||||
var authRequired = !publicPages.includes(to.path) && !to.path.startsWith('/join');
|
||||
const loggedIn = localStorage.getItem('user');
|
||||
|
||||
if (to.path.startsWith('/room/')) {
|
||||
if (to.hash && to.hash.startsWith('#')) {
|
||||
//Invite to public room
|
||||
router.app.$matrix.setCurrentRoomId(to.hash);
|
||||
authRequired = false;
|
||||
}
|
||||
}
|
||||
|
||||
// trying to access a restricted page + not logged in
|
||||
// redirect to login page
|
||||
if (authRequired && !loggedIn) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue