Jelajahi Sumber

Fixed station routes

theflametrooper 8 tahun lalu
induk
melakukan
fd945d4c8b
1 mengubah file dengan 28 tambahan dan 3 penghapusan
  1. 28 3
      frontend/main.js

+ 28 - 3
frontend/main.js

@@ -59,6 +59,28 @@ router.beforeEach(transition => {
 	} else {
 		transition.next();
 	}
+
+	if (transition.to.officialRequired) {
+		io.getSocket(socket => {
+			socket.emit('stations.findByName', transition.to.params.id, res => {
+				if (res.status === 'success') {
+					if (res.data.type === 'community') transition.redirect(`/community/${transition.to.params.id}`);
+					else transition.next();
+				}
+			});
+		});
+	}
+
+	if (transition.to.communityRequired) {
+		io.getSocket(socket => {
+			socket.emit('stations.findByName', transition.to.params.id, res => {
+				if (res.status === 'success') {
+					if (res.data.type === 'official') transition.redirect(`/official/${transition.to.params.id}`);
+					else transition.next();
+				}
+			});
+		});
+	}
 });
 
 router.map({
@@ -111,13 +133,16 @@ router.map({
 		adminRequired: true
 	},
 	'/official/:id': {
-		component: Station
+		component: Station,
+		officialRequired: true
 	},
 	'/:id': {
-		component: Station
+		component: Station,
+		officialRequired: true
 	},
 	'/community/:id': {
-		component: Station
+		component: Station,
+		communityRequired: true
 	}
 });