Routers make use of the IP address, etc to shape the traffic. So obviously they must reside in at least the Network layer. However we can also shape the traffic using tcp/udp. Routers usually have the port forwarding feature which allows them to shape the tcp/udp traffic.
The IP header has a field for protocol. However that doesn't show whether the traffic is udp/tcp. This information must be present inside the payload part of the IP packet. Then why is the router able to see that information despite being in the Network Layer?