From: Kai Moritz Date: Sat, 7 Jan 2023 18:44:03 +0000 (+0100) Subject: fix: chatroom redirects to chatrooms, if the chatroom-id is missing X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=16757be5a8c3501ff0b0f4f87bb4068a4363cabf;p=demos%2Fkafka%2Fchat fix: chatroom redirects to chatrooms, if the chatroom-id is missing --- diff --git a/src/app/chatroom/chatroom.component.ts b/src/app/chatroom/chatroom.component.ts index a25b09c0..7178a5a8 100644 --- a/src/app/chatroom/chatroom.component.ts +++ b/src/app/chatroom/chatroom.component.ts @@ -1,5 +1,5 @@ import { Component, OnInit, NgZone } from '@angular/core'; -import { ActivatedRoute } from '@angular/router'; +import { ActivatedRoute, Router } from '@angular/router'; import { ChatroomService } from "../chatroom.service"; import { UserService } from "../user.service"; import { Chatroom } from "../chatroom"; @@ -16,6 +16,7 @@ export class ChatroomComponent implements OnInit { messages: Message[] = []; constructor( + private router: Router, private chatroomsService: ChatroomService, private userService: UserService, private route: ActivatedRoute, @@ -30,6 +31,7 @@ export class ChatroomComponent implements OnInit { const id: string | null = this.route.snapshot.paramMap.get('id'); if (id === null) { console.log("ID for chatroom is missing in URI"); + this.router.navigate(['chatrooms']); } else { this.chatroomsService