How can one avoid ectopic pregnancy?

I have some close relatives who have experienced ectopic pregnancies. Iím just wondering if such kind of pregnancy can be avoided or inherited. What are the risks of experiencing this kind of pregnancy?