The simplest way to stop bleeding from a minor cut like a shaving nick is to apply direct pressure (a clean fingertip does the job nicely) for at least two minutes.
If you take blood thinners or have a low-grade clotting disorder, it might take ten to thirty minutes or more for clotting to occur, and the time must be restarted if you remove the pressure and bleeding restarts. If you have full-blown hemophilia, you shouldn't be shaving at all, by any method (even an electric razor can skim off raised skin around a follicle and cause bleeding), though your doctor may suggest a trimmer with a suitable guard to control beard length.
Obviously, if you have to hold pressure for ten minutes or more to stop bleeding, you'll need to reapply your choice of shaving foam or soap before you can finish shaving, but if that applies to you, you should consider shaving by a method less likely to cause bleeding, such as an electric foil shaver.