It's often recommended to belay off the harness (an "indirect" belay) when belaying the leader, and off the anchor (a "direct" belay) when belaying the follower. Use of an indirect belay for the leader reduces the force on the anchors, but does require consideration of how the belayer may be pulled in a fall. Use of a direct belay for the follower similarly minimizes the force on the anchor by avoiding the pulley effect.
When the anchor pieces are extremely solid (e.g. bolts), a direct belay may be desirable in both cases. Still, do bear in mind that neither setup is mandatory; if a direct belay would place you in an awkward or less secure position then an indirect belay would offer, you should probably use the indirect belay and vice versa.
Belaying the leader
Should the leader fall before placing any protection, and continue falling past the belayer, the direction of pull then comes from below, and so the belayer must reverse their braking direction. As the belayer may not recognize the implications of this and thus not respond quickly enough, it's common to want to find some way to redirect the rope. However, an easier way to address this is for the belayer to bring their brake hand around behind their hip, rather than making a habit of braking purely downwards. Having your hand further from the device when it's locked-off may also reduce rope burns in a high fall factor situation as more rope can slip through the device before it has to also slip through your hand.
If a redirect is still wanted, the leader can do this by clipping the rope into the shelf, master point, or the topmost piece of the anchor, which the belayer may unclip once additional protection has been placed. Alternatively the belayer could lower themselves a few meters below the anchor. I've also seen it suggested that the previous leader could climb slightly above the belay station in order to place an initial piece, and descend to build the belay anchor. (This makes an exception to the "never back-clip" rule, as back-clipping this piece lets the rope run the correct direction when the other climber takes the lead.)
Redirecting the belay by clipping the anchor may slightly reduce the fall factor due to the additional rope out. However, it also means the belayer will be pulled violently into that piece when such a fall happens. The pulley effect will also multiply the force on the anchor (or the particular piece that was clipped) in contrast to a direct belay. Thus, unless the clipped piece is solid (e.g. a bolt) and the belayer can also be anchored to prevent them smashing into it, it may be preferable for the leader to simply place good protection soon after leaving the ground rather than clipping the leader's rope into the anchor. (Of course, if you have an extremely solid anchor, you might also consider a direct belay.)
A strong argument for an indirect belay (off the harness) is that by incorporating the belayer into the system, some of the load on the anchor is shifted to the belayer's stance. This may be helpful if the quality of the anchor or gear is in question. If you do use an indirect belay, be mindful of the direction a fall will pull the belayer. It's also advisable to clip the belay device into both the rope tie-in loop and the belay loop when doing this, in order to prevent discomfort from the harness being twisted in two different directions. (Clipping the belay loop vs. clipping the tie-in loop is also a way you can further adjust the amount of force going to the anchor.)
On the other hand, a direct belay (off the anchor) will be much easier to escape if something goes wrong, and essentially eliminates the weight of the belayer as a factor in catching falls. This may be beneficial if the leader significantly outweighs their belayer, but it also means that it's harder to give a "soft catch". It also places significantly higher forces on the anchor and gear. (Along those same lines, use of a tube-style belay device such as an ATC or Reverso will allow additional rope slippage that further reduces the impact on the anchor.)
Will Gadd "Anchor Clipping #2 (Now 3)
Belaying – From the 'Rope Loop' or from the harness 'Belay Loop'?
Max Berger "Steinzeitmethode Fixpunktsicherung?"