From 7165b5af8c9c014e1b0f80e464a80e9677b6e3f5 Mon Sep 17 00:00:00 2001 From: N-Pex Date: Tue, 12 Jan 2021 20:51:31 +0100 Subject: [PATCH] More navigation work A normal room link https://server.com/#/room/#PUBLIC:matrix.org will now redirect to the /join/ screen if you are not logged in or not joined. --- src/components/Chat.vue | 2 +- src/components/Login.vue | 4 ++-- src/router/index.js | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/components/Chat.vue b/src/components/Chat.vue index ebce1f7..fbfad7d 100644 --- a/src/components/Chat.vue +++ b/src/components/Chat.vue @@ -338,7 +338,7 @@ export default { room: { immediate: true, handler(room, oldRoom) { - if (room == oldRoom) { + if (room && room == oldRoom) { return; // No change. } console.log("Chat: Current room changed"); diff --git a/src/components/Login.vue b/src/components/Login.vue index 402a1c6..8825173 100644 --- a/src/components/Login.vue +++ b/src/components/Login.vue @@ -75,7 +75,7 @@ export default { }, created() { if (this.loggedIn) { - this.$navigation.push({name: "Chat", params: { roomId: null }}, -1); + this.$navigation.push({name: "Chat", params: { roomId: this.$matrix.currentRoomId }}, -1); } }, watch: { @@ -114,7 +114,7 @@ export default { this.loading = true; this.$store.dispatch("auth/login", this.user).then( () => { - this.$navigation.push({name: "Chat", params: { roomId: null }}, -1); + this.$navigation.push({name: "Chat", params: { roomId: this.$matrix.currentRoomId }}, -1); }, (error) => { this.loading = false; diff --git a/src/router/index.js b/src/router/index.js index 6586562..e44032a 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -15,7 +15,7 @@ const routes = [ component: Chat }, { - path: '/room/:roomId', + path: '/room/:roomId?', name: 'Chat', component: Chat }, @@ -47,11 +47,11 @@ router.beforeEach((to, from, next) => { var authRequired = !publicPages.includes(to.path); const loggedIn = localStorage.getItem('user'); - if (to.name == 'Join' && !to.params.roomId && to.hash) { - to.params.roomId = to.hash; - } - if (to.name == 'Chat' || to.name == 'Join') { + if (!to.params.roomId && to.hash) { + // Public rooms start with '#', confuses the router. If hash but no roomId param, set it. + to.params.roomId = to.hash; + } const roomId = util.sanitizeRoomId(to.params.roomId); router.app.$matrix.setCurrentRoomId(roomId); if (roomId && roomId.startsWith('#')) {