diff --git a/projectSecondPart/src/photo-share/components/top-bar/TopBar.jsx b/projectSecondPart/src/photo-share/components/top-bar/TopBar.jsx
index d058ca4860938ca4552e54cd9fbf2a26e859deee..1eae74013ac0b221b289f1ce731349a6204bbf2a 100644
--- a/projectSecondPart/src/photo-share/components/top-bar/TopBar.jsx
+++ b/projectSecondPart/src/photo-share/components/top-bar/TopBar.jsx
@@ -27,13 +27,15 @@ class TopBar extends React.Component {
 
 	updateHeader = (pathname) => {
 		const path = pathname.split('/');
-		const user = PROG2053Models.userModel(path[3]);
-		let newContext = '';
-		if (path[2] === 'photos') {
-			newContext += 'Photos of ';
+		if (path[2] && path[3]) {
+			const user = PROG2053Models.userModel(path[3]);
+			let newContext = '';
+			if (path[2] === 'photos') {
+				newContext += 'Photos of ';
+			}
+			newContext += `${user.first_name} ${user.last_name}`;
+			this.setState({headerContext: newContext});
 		}
-		newContext += `${user.first_name} ${user.last_name}`;
-		this.setState({headerContext: newContext});
 	};
 
 	render() {