When a hub receives a packet of data at one of its ports from a PC on the network, it transmits (repeats) the packet to all of its ports and, thus, to all of the other PCs on the network. At the same time others try to send the packets, there is chance to occur traffic that is technically called Collision The process is prescribed in the Ethernet Carrier Sense Multiple Access with Collision Detection (CSMA/CD) protocol.
Switch uses different technology that it automatically divides the network into multiple segments. Since it maintains the table of each destination address and its port, it supports multiple connections simultaneously. When the switch receives apacket, it reads the destination address from the header information in the packet, establishes a temporary connection between the source and destination ports, sends the packet on its way, and then terminates the connection. In OSI Reference Model Switch operates in Layer 2 that is Data link Layer.
A Router is an intelligent device to manipulate and route the data its being asked. It is designed to connect multiple area networks like LAN and WAN. In industry starts from broadband router to industry standard router like branded CISCO used to find the best path to forward the packets. In OSI Reference Model router operates in layer 3 that is Network layer.