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.
This commit is contained in:
N-Pex 2021-01-12 20:51:31 +01:00
parent 0130858908
commit 7165b5af8c
3 changed files with 8 additions and 8 deletions

View file

@ -338,7 +338,7 @@ export default {
room: { room: {
immediate: true, immediate: true,
handler(room, oldRoom) { handler(room, oldRoom) {
if (room == oldRoom) { if (room && room == oldRoom) {
return; // No change. return; // No change.
} }
console.log("Chat: Current room changed"); console.log("Chat: Current room changed");

View file

@ -75,7 +75,7 @@ export default {
}, },
created() { created() {
if (this.loggedIn) { if (this.loggedIn) {
this.$navigation.push({name: "Chat", params: { roomId: null }}, -1); this.$navigation.push({name: "Chat", params: { roomId: this.$matrix.currentRoomId }}, -1);
} }
}, },
watch: { watch: {
@ -114,7 +114,7 @@ export default {
this.loading = true; this.loading = true;
this.$store.dispatch("auth/login", this.user).then( 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) => { (error) => {
this.loading = false; this.loading = false;

View file

@ -15,7 +15,7 @@ const routes = [
component: Chat component: Chat
}, },
{ {
path: '/room/:roomId', path: '/room/:roomId?',
name: 'Chat', name: 'Chat',
component: Chat component: Chat
}, },
@ -47,11 +47,11 @@ router.beforeEach((to, from, next) => {
var authRequired = !publicPages.includes(to.path); var authRequired = !publicPages.includes(to.path);
const loggedIn = localStorage.getItem('user'); 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.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); const roomId = util.sanitizeRoomId(to.params.roomId);
router.app.$matrix.setCurrentRoomId(roomId); router.app.$matrix.setCurrentRoomId(roomId);
if (roomId && roomId.startsWith('#')) { if (roomId && roomId.startsWith('#')) {