If you had a knee replacement, we prefer you sleep on your back with the leg in full extension for two weeks.
If you had a hip replacement, you can sleep on your nonsurgical side whenever it is comfortable. You can sleep on your surgical side when the wound has healed, about 4 weeks.
If you had a revision hip replacement, you may not be able to sleep on your side for 4-6 depending if there are any formal hip precautions to help prevent a dislocation.