The router decides where data has to go. You wouldn't get anywhere on networks without it. Way back, when networks were just getting started, there weren't routers. It was the genius of companise like Cisco to realise that this was not the best way to do things. Pretty soon, there would be so much routing to do, that we would need specialist devices to do it, with their own hardware, and their own specialist software.
Routers look at packet headers, and use a table to decide where to send the packets.
The routing table is built up by communicating with other routers to understand the best routes between hosts. But nothing stands still for long. In local area networks , routers are being replaced by switches, and on the backbone, new kinds of faster routers are coming in. The drive for all of this is the simplification that is taking place as the old variety of network protocols is replaced by the simplicity of just doing everything on IP . That, and the increasing intelligence available in the hardware.