I've always read, the router is a layer 3 device, the switch is a layer 2 device, the hub and repeater are layer 1 devices and so on with other devices.
But what does this mean? When I started studying this topic, about 2 months ago, I thought I had understood it, and had defined it as
A layer N device is a device that implements up to layer N of the OSI model and whose main function occurs in that layer N.
So I liked that definition, because I made sense of it.
For example, for a router, it implemented layers 1, 2 and 3 and its main function occurred at the network layer.
However, some time later, I asked myself the question:
If the router implements layers 1,2 and 3 this means that it has to perform all the functions that are executed in layer 1, in layer 2 (framing, error correction/detection, MAC, etc.) and also the functions Layer 3 (Routing, subnetting, etc.)
On the other hand, the Switch implements layer 1 and 2.
So my inference was that the Router would perform all the functions that the Switch does and more, because it implements more layers.
So why would we want a switch, hub or repeater when we have a router that implements the same layers and more?
I know that in reality this is not the case, but it is difficult for me to see what concepts I am confusing and where my definitions are failing.
Thank you very much in advance.