To prevent miscarriage or other medical conditions, doctors may sometimes prescribe low-dose aspirin to pregnant women. However, generally speaking, if you need pain relief, it is best for pregnant women to avoid taking aspirin or other non-steroidal anti-inflammatory drugs (NSAIDs) such as ibuprofen.
Before birth, the fetus receives oxygen through the placenta. At birth, the prostaglandin levels in the baby's body naturally drop, prompting the baby to start using their lungs for oxygen. Aspirin interferes with prostaglandin synthesis, so taking aspirin during pregnancy (especially after 32 weeks) can prematurely alter the baby's oxygen intake method, potentially leading to fatal consequences.
If you need pain relief during pregnancy, consult your doctor. They may allow you to occasionally use acetaminophen (paracetamol), which is considered relatively safe for pain relief during pregnancy.