Both, in a way. On an IP level, your computer knows that it's going to an external address, and sends it directly to the router because it knows that the router is acting as a gateway for anything not on the local subnetwork (which it determines by using the subnet mask).
However, switches and hubs operate one level below IP, the ethernet level (specifically, the Data link layer, with IEEE 802 ethernet for wired ethernet and WiFi devices). It doesn't know what an IP address is, or what they mean. However, it does understand something called a MAC address. When your computer sends out a packet, it also includes the MAC address of the next device on the network which should be handling that packet. In this case, the router.
When a hub receives a packet, it does exactly what you described - it duplicates the packet and sends it out over all lines in hope of getting it to its destination. Any devices that receive the packet but are not the recipient simply discard it.
A switch, on the other hand, is a bit smarter. It actually keeps a table of MAC addresses and associates them with each port, based on incoming traffic. That way, when it has to send a packet to a specific MAC address, it knows which port it needs to send out on. This helps to reduce network congestion.