Sometimes root canal treatment (RCT) can be prevented and sometimes it cannot. In all cases, infection and/or tooth "nerve" (dental pulp) inflammation, called pulpitis, are the considerations. Pulpitis can be caused by tooth decay, trauma or diseases of the tooth's pulp. Treatment of tooth decay before it reaches the tooth’s pulp usually prevents the need for RCT. Some typical trauma events are sports injuries, falls and spontaneous tooth fractures, usually while chewing. Diseases of the pulp include certain dental problems (e.g. resorption) and certain medical causes (e.g. blockage of the pulp's microscopic blood vessels due to sickle cell anemia or diabetes.)
Your dentist diagnoses pulpitis by (i) X-rays, (ii) symptoms, and (iii) pulp testing (electrical, cold, hot, other) as either reversible or irreversible.
If your problem is reversible pulpitis, it can be treated. If treatment heals the tooth, it may prevent the need for root canal. This includes (i) treatment for tooth decay like a filling or, for deep tooth decay, medicating the deep portion near the pulp to initiate healing; (ii) treatment for sports injuries like bite adjustments and splinting, and (iii) treatment for fractured teeth like restorations or crowns (caps.) There are numerous other possible treatments for reversible pulpitis.
If your problem is irreversible pulpitis, root canal treatment is a good option. It can eliminate the pain and/or infection and extend the useful life of the tooth. Exposure of the pulp due to tooth decay or trauma usually results in irreversible pulpitis. Diseases of the pulp and medical causes of pulpitis, as described above, are almost always irreversible.
Ask your dentist for treatment alternatives. Many general dentists do RCT and many refer difficult cases to specialists known as endodontists. "Endo" is dentist speak for root canal treatment.